简体   繁体   中英

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.

  • 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 {

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM