点击应用程序图标时无法获得推送(远程)通知

Unable to get push (remote) notification when app icon tapped

根据 Local and Remote Notification Programming Guide,当发送远程通知并且您点击 SpringBoard 中的应用程序图标时:

The user taps the default button in the alert or taps (or clicks) the app icon. If the default action button is tapped (on a device running iOS), the system launches the app and the app calls its delegate’s application:didFinishLaunchingWithOptions: method, passing in the notification payload (for remote notifications) or the local-notification object (for local notifications).

If the notification is remote, the system also calls application:didReceiveRemoteNotification:fetchCompletionHandler:.

但是,当我看到远程通知标志并点击应用程序图标时,application:didFinishLaunchingWithOptions:(应用程序将在后台 运行)、application:didReceiveRemoteNotification:application:didReceiveRemoteNotification:fetchCompletionHandler: 被称为...

我在点击横幅或警报时成功获取了推送通知的有效负载,我如何在点击应用程序图标时也能获取它?

谢谢

您需要继续阅读。您引用的部分的其余部分是 -

If the app icon is clicked on a computer running OS X, the app calls the delegate’s applicationDidFinishLaunching: method in which the delegate can obtain the remote-notification payload. If the app icon is tapped on a device running iOS, the app calls the same method, but furnishes no information about the notification.

注意我加粗的部分。简短的回答是,如果应用程序是从应用程序图标启动的,则不会提供有关可能已收到的任何通知的信息。

我 运行 遇到了同样的问题,不幸的是就像 Paulw11 所说的那样,您的应用程序将不会收到有关负载的任何信息。然而!我注意到徽章编号会反映错过的通知,因此在应用程序启动时,您可以检查您的 applicationBadgeNumber != 0 是否存在,如果不是,您可以查询服务器以获取发送的最后数据。