0

As I can see in the APNS documentation, silent notifications are handled in didreceiveremotenotification if the app is not running, but they have an low priority. So sometimes my iOS application doesn't receive silent notifications.

Does iOS show non silent notifications, if the app is not running (not in foreground, not in background)? And will a non silent notification trigger the didreceiveremotenotification?

4

1 回答 1

2

For non silent notifications,

didreceiveremotenotification will be triggered if the app is in active or inactive state. Not when terminated or suspended state. In case of terminated or suspended state when user taps on notification app will be launched by calling didFinishLaunchingWithOptions and launchingOptions will have the payload as Dictionary.

In case you provide UNNotificationServiceExtension then iOS will call didReceive(_:withContentHandler:) on receiving the notification and you can use it to customize the content of a remote notification before it is delivered to the user. read:https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension

In case you provide UNNotificationContentExtension then iOS will call the didReceive on receiving the notification and you can use it custom load notification content.

Read : https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension

P.S:

Normal notifications can not be used as an alternative/work around to silent notification just because you cant use silent notification in app terminated state.

Silent notifications are intended for syncing the client app with the updated content available at server. As this can be done without the explicit user interaction silent notification can be used.

Silent notifications must contain content-available key and must not contain alert, sound, or badge keys. read : https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

Where as in case of normal notification, there is no way to hide notification banner/alert/sound unless the user setting on phone says so.

于 2017-10-05T09:24:33.323 回答