Pregunta

I googled a lot, but I can´t find the answer.

I'm trying to get the content / payload of a push notification while the app is in background.

The method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

and

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

doesn't work.

¿Fue útil?

Solución

If you don't have any background mode for the application (one of audio, gps or voip) the method -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo will be called not instantly but after the user press "Open" button bringing the app to foreground. If he or she decides to skip the notification you can do nothing about it, meaning you need to refresh the state when the application is back to foreground, you can not rely on the push notifications to update the data.

The better option might be to use the badge counter to track the changes, you need to calculate it on the server side. Then if the app in the foreground has the positive badge number you do update the data and reset the counter. However that's not perfect as there's no warranty the notification is delivered - you still need to check the badge counter (or you can say to check the number of changes) manually.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top