1

I have a problem with push notifications in iOS, in a similar scenary to this and this and another one.

Also, this post resume all possible situations. In my case:

  • app is NOT RUNNING
  • content-available:1
  • UIBackgroundModes contains 'remote-notifications' and 'fetch'

If the user force-quit the app and receives a push notification, then it could open app from alert or from icon. When the user tap on the notification the app will be opened and the following method will be executed:

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Handle for notifications when app is closed
    if (launchOptions) { 
        NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];

        if (apsInfo) { 
            // handle notification 
        }

    }

No problem up to here, I have the payload to doing something with that info (for example to fetch new data from server).

But if the user open the app from the icon I don't have any way to handle the payload (Although didFinishLaunchingWithOptions is execute, I don't have the aps info, according to docs here).

So, the question is, there are any way to solve that? For example, I made the test with WhatsApp, and they handle that situation, (probably they are using VOIP notifications instead of Remote Notifications)

Regards

Community
  • 1
  • 1
Fer Juarez
  • 55
  • 1
  • 5
  • 1
    My guess is that they are loading the data from a remote server through an API when the app becomes active, and not from the notification. – Meriw Feb 16 '16 at 17:18
  • Thanks for the reply, yes this is another option. But I have the doubt about the possibilities from the client side. – Fer Juarez Feb 16 '16 at 18:03
  • Dear Fe Juarez,**I am also stucking to this** since last week but couldn't solve yet,could you solve this..?? If you **got any idea,description,example,code** about this please shear me.Thanks in advance! – vky Dec 27 '17 at 11:32

1 Answers1

2

You should never assume that state has remained consistent between the time the notification has been delivered and the time the user has launched the app. Nor, even, that it is the same device. I'll frequently get a "Hey! Do something!" notification on my phone and, if my iPad is handy, respond to it on my nice big iPad screen.

Instead, you should round trip to the server and grab the most up to date state for that user at the time of app launch or activation.

bbum
  • 162,346
  • 23
  • 271
  • 359
  • 1
    You're right. But in case of WhatsApp for example, if the app is close and a new notification arrives (and your device is in airplane mode) the list of messages showed before open the app are updated. So, I think that list was updated from notification. – Fer Juarez Feb 16 '16 at 18:07
  • Sure-- they may also be pulling info from the notification itself. Effectively, your message stream is a hunk of time series data where the events in the stream may be edited (deleted). Your clients have to track both the last time they've seen the stream and a means to track edited content from prior. The notification payload may provide a set of recent time series events, but you'll eventually need to round-trip to the server to regain the "truth". And you might also need consider pushing "has seen" back to the server for user's other client devices. – bbum Feb 16 '16 at 18:28