我有一个关于在这种情况下检索有效负载(userInfo)的问题:
该应用程序在后台运行或未启动.应用程序收到推送通知,显示横幅,播放声音,显示消息,增加应用程序图标徽章,并在iOS通知中心中显示推送通知.如果用户在显示通知时或在通知中心点按通知,则会启动应用程序,并调用didReceiveRemoteNotification:方法.
但是,如果用户只是点击应用程序图标并以正常方式启动应用程序,则不会调用该方法,并且无法检索userInfo.
来自Apple的documentation on handling push notifications:
The notification is delivered when the app isn’t running in the foreground. In this case,the system presents the notification,displaying an alert,badging an icon,perhaps playing a sound,and perhaps displaying one or more action buttons for the user to tap.
The user taps a custom action button in an iOS 8 notification. In this case,iOS calls either application:handleActionWithIdentifier:forRemoteNotification:completionHandler: or application:handleActionWithIdentifier:forlocalnotification:completionHandler:. In both methods,you get the identifier of the action so that you can determine which button the user tapped. You also get either the remote or local notification object,so that you can retrieve any information you need to handle the action.
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). Although application:didFinishLaunchingWithOptions: isn’t the best place to handle the notification,getting the payload at this point gives you the opportunity to start the update process before your handler method is called.
If the notification is remote,the system also calls 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.
突出显示的部分有点说没有明显的方法以这种方式访问推送通知的有效负载.那么有办法解决这个问题吗?
谢谢!
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。