iOS - Handling pushed notifications with APNS

后端 未结 1 1569
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 06:20

Considering that I receive a pushed notification on my iPhone.

What happens:

  1. If the application is started: is there a way to get the payload? Do I see th
相关标签:
1条回答
  • 2021-02-04 06:57

    First of all push notifications are not “strong”, if you simply let a notification sit for long enough (e.g. phone turned off for many days) it will get discarded. You need to do some custom back-end processing to persist the content sent in notifications.

    In the UIApplicationDelegate protocol there’s application:didFinishLaunchingWithOptions:. If your app is launched by the user tapping the right button in an alert of a push notification, the launchOptions dictionary bound to the method call will contain information regarding that notification; if your app is already running then application:didReceiveRemoteNotification: (also in the delegate protocol) will get called instead.

    So,

    • If the application is started, and you implement application:didReceiveRemoteNotification: then yes you get the payload. Otherwise, nothing happens.

    • If the application is not started at the time the notification is sent, then the user taps on the alert of the notification and launches your app, your app gets the payload if it implements application:didFinishLaunchingWithOptions:. Otherwise, you get nothing.

    0 讨论(0)
提交回复
热议问题