1
votes

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

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
Thanks for the reply, yes this is another option. But I have the doubt about the possibilities from the client side.Fer Juarez
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

1 Answers

2
votes

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.