2
votes

Consider this scenario:

1) Launch the app

2) Put the app in background (pressing Home button)

3) Server send a PUSH notification to client

4) The user resume the app clicking on its icon from menu

In this case didReceiveRemoteNotification and didFinishLaunchingWithOptions are not called, so how do I get notifications ?

3
Why wouldn't didReceiveRemoteNotification be called? I think I'm confused about that. The user is either going to get an alert that pops up while the app is closed or if the app is running, that method is going to fire and you can handle the notification however is appropriate. Is there some timing issues/bug I haven't encountered before that causes didReceiveNotification not to fire because it currently works in the practice apps I'm working with.George Clingerman
didReceiveRemoteNotification is called if you click on notification while the app is in background, not if you resume the app clicking on its iconech0s7r
That method is most definitely called if the app is running. The docs and my own projects both verify that. If the app is active in memory (i.e. currently in the foreground) didReceiveRemoteNotification is called.George Clingerman
didReceiveRemoteNotification is called if the app is in foreground, and after that you resume the app clicking on notification from status bar, but not after resume by clicking on app icon (and there is a notification pending)ech0s7r

3 Answers

2
votes

Simple answer: In this scenario you cannot get it.

If the push notification contains important payload then it should not contain it because you should not rely on it for anything important because:

  • notifications are not guaranteed to be delivered to the device in the first place

  • the user can turn off notifications

  • they could ignore them

  • if the device is turned off when it is due to be displayed then it will be lost

If you need to know if the server has sent a notification then make a connection home when you become active and ask it if it did so.

0
votes

You should check in the applicationWillEnterForeground: method.

0
votes

I think the app will not see anything if the user chooses to ignore the push notification. The workaround that comes into mind first would be to offer a way of checking the server if anything worth a push notification has happened since the last time the app was opened and correlating that with the local data.

I think the idea behind this system is to separate actual functionality from push notifications and making sure the notifications are used for only one purpose - notifying of new data/event/etc, thus leaving the downloading and processing of data to the app once it's fully in the foreground. I.e everything should be duplicated in the launching sequence to make sure the app is always up-to-date, even if the notifications during downtime were not received/ignored.

application:didReceiveRemoteNotification: is therefore meant for not transferring the data and updating the model, but reacting to the event and starting the necessary procedures. Although most of the time, the data may be so small that it fits in the notification and therefore the application can proceed without downloading any further content.