9

When receive a push notification and my application is totally closed, how can handle this info?

Only can get data from NSDictionary on this method didFinishLaunchingWithOptions: or

didReceiveRemoteNotification:

for example: when the user open the application how get data from the push notification?, and not when the user open the push notification directly.

Is there a method that responds and detect if a notification has not been read?

Fabio
  • 1,913
  • 5
  • 29
  • 53

1 Answers1

17

You'll want to implement

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler

This will launch your app if needed, then you'll want to save the data somewhere so when the user next's starts the app you grab the data and do something with it.

From Apples Doc's:

Discussion

Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a push notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

Just look into the method and I'm certain you'll figure it out :)

I did a quick google, these look like they will help:

SO example: didReceiveRemoteNotification: fetchCompletionHandler: open from icon vs push notification

The first tutorial i saw on it: http://hayageek.com/ios-background-fetch/

BooRanger
  • 1,516
  • 1
  • 14
  • 18
  • 3
    I have a quick question. If I close the app from the multitask screen will I still be able to receive a notification? Because on my end, seems like I can't receive a notification when I close the app. – Rhenz Nov 03 '15 at 16:23
  • 1
    @BooRanger Thank you so much for your answer !!!!! Love You ( Not appropriate though ) – Hyder Nov 12 '15 at 09:31
  • 1
    @BooRanger thanks, a lot I spent looooooooong time looking for this – Shehabic Jan 18 '16 at 20:05