iOS检索远程通知负载

我已经实现了UIApplicationDelegate方法 – (void)应用程序:(UIApplication *)应用程序didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler来处理推送通知,它工作正常.在某些情况下,我需要检索推送通知的有效负载.但有时这种委托方法不会被调用.

我有一个关于在这种情况下检索有效负载(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.

突出显示的部分有点说没有明显的方法以这种方式访问​​推送通知的有效负载.那么有办法解决这个问题吗?

谢谢!

解决方法

这是iOS的认行为.除非用户通过点击通知打开您的应用,否则您永远不会知道有效负载.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...