Delegate for “View” for Push Notification

2019-06-09 14:17发布

问题:

Is there any delegate which gets called when we tap on the "View" button of Push Notification alert. This is when App is inactive.

回答1:

Yes there is. It is application:didFinishLaunchingWithOptions:. From the Apple docs:

If the action button is tapped, the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications). If the application icon is tapped, the application calls the same method, but furnishes no information about the notification.

Here is the reference: Local and Push Notification Programming Guide Look at the Handling Local and Remote Notifications section.



回答2:

From a glance at the Push Notification docs, it looks like you get the notification in application:DidFinishLaunchingWithOptions: and can retrieve the notification info from the options dictionary using UIApplicationLaunchOptionsRemoteNotificationKey.



回答3:

There is no way to get notification payload when app is in background, because when icon is tapped applicationDidEnterForeground is called and in this method we cannot access launchOptions OR userInfo dictionary.