[英]Getting push notification payload when user opens app manually after push has been received in the background
I am using iOS7 and I am trying to determine if I can get the JSON payload in the following situation. 我正在使用iOS7,并且试图确定在以下情况下是否可以获取JSON有效负载。
When I launch the app from the icon itself after the notification has been received I do not get the push in the launch options from 收到通知后,我从图标本身启动应用程序时,我没有从
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
and the following method does not get called either when app is manually launched from the icon 从图标手动启动应用程序时,以下方法也不会被调用
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
I finally figured out how you can get this! 我终于想出了如何得到这个!
As of iOS 7 you can get it! 从iOS 7开始,您可以获得它!
Basically, you need to configure your application for background remote notifications. 基本上,您需要为后台远程通知配置应用程序。
So, in your info.plist file: For required backgrounds
- set it to app downloads content from push notifications.
因此,在您的info.plist文件中:
For required backgrounds
-将其设置为app downloads content from push notifications.
In the AppDelegate.m
file, you need to implement this method: 在
AppDelegate.m
文件中,您需要实现此方法:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
See this for how to implement that: didReceiveRemoteNotification: fetchCompletionHandler: open from icon vs push notification 请参阅此内容以了解如何实现该功能:didReceiveRemoteNotification:fetchCompletionHandler:从图标打开与推送通知
For your push notifications, you must have 'content-available': 1,
as part of the push notification. 对于您的推送通知,您必须具有
'content-available': 1,
作为推送通知的一部分。 This is what tells the application that there is new content before displaying the alert. 这就是在显示警报之前告诉应用程序新内容的原因。
See this page for more information on background remote notifications: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/ 请参阅此页面以获取有关后台远程通知的更多信息: http : //developer.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.