Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle multiple push notifications with user data arrived at different times?

My app is receiving APNs sent from server to Apple backend. Naturally a user may not open the app once a notification arrives to user's device. In meantime my server may push more notifications. They all contain some user data that is important when a notification is processed. So how to deal with it? iOS won't bundle and give me a batch, will it?

Here are ways how I am going to tackle it, none of which is simple.

  1. Server keeps track of not seen data and upon arriving a new request always sends a batch of all new notifications, reflecting the count as badge count.
  2. Client is opened by taping on notification popup. In this case it has all needed data in didReceiveRemoteNotification. OR
  3. Client ignores notification popup and opens app (possibly later) by tapping on app icon. In this case didReceiveRemoteNotification is not called and thus app has to fetch all needed data from server. OR
  4. Server never sends any user data and client always checks for new stuff every time it starts or fetches data in didReceiveRemoteNotification.

Anything else? Something simpler I am missing?

like image 987
Schultz9999 Avatar asked Nov 12 '22 21:11

Schultz9999


1 Answers

Number 4 is the right approach. There is no guarantee that any of your app code will run when an APN is received, except on iOS7. So when your app starts, it has to check with your servers for any new information that it should display.

It's simplest to code this to alway ask your servers for the latest information to display, rather than rely on the information in the APN. Use the information in the APN only to determine which new information to navigate to, so that the app displays whatever the user tapped on.

This has changed with iOS7, where you can use the remote-notification background mode to be launched whenever a push message arrives. See https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:

like image 86
Malcolm Box Avatar answered Nov 15 '22 07:11

Malcolm Box