Delegate for “View” for Push Notification

2019-06-09 13:50发布

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

3条回答
爷的心禁止访问
2楼-- · 2019-06-09 14:23

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-09 14:29

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.

查看更多
叛逆
4楼-- · 2019-06-09 14:35

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.

查看更多
登录 后发表回答