Getting push notification payload when user opens app manually after push has been received in the background

拥有回忆 提交于 2019-12-11 02:04:16

问题


I am using iOS7 and I am trying to determine if I can get the JSON payload in the following situation.

  • I have background mode "remote-notifications" enabled
  • The push notification is received while the app is terminated
  • The app is launched manually from the icon not from the notification center

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 {


回答1:


I finally figured out how you can get this!

As of iOS 7 you can get it!

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.

In the AppDelegate.m file, you need to implement this method:

- (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

For your push notifications, you must have 'content-available': 1, as part of the push notification. 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/



来源:https://stackoverflow.com/questions/21859012/getting-push-notification-payload-when-user-opens-app-manually-after-push-has-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!