Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Push Notifications with empty aps dictionary

Doing research to try and pick a direction for notification types. I'd like to be able to notify my app that there's new data to be refreshed but not bother the user with the popup/notification message. The idea is that the same notifications go out if the app is open or closed and when this "special" message arrives and the app is open it knows to fetch data.

My idea was to send an empty aps dictionary like example 5 at the bottom of this apple document.

My question is what will happen when this type of message is received? It says it'll clear the badge but will some sort of default message appear to the user? Or will this be completely silent?

Follow up question, is there some better way to do this other than checking if the app is running and telling my server to start sending "special" payloads (I'd like to handle everything through push)?

like image 226
NKijak Avatar asked Nov 30 '11 22:11

NKijak


People also ask

What is the difference between push notifications and in app messages?

In-app notifications vs push notificationsIn-app messages differ from push notifications because of the user state each one target. The former communicates with people who are currently using the application while the latter sends apps outside the app to get the attention of users who don't currently have it open.

Do push notifications work when app is closed iOS?

Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.

Will iOS awake my app when I receive silent push notification?

Silent remote notifications can wake your app from a “Suspended” or “Not Running” state to update content or run certain tasks without notifying your users. To use silent remote notifications to trigger background work, set up the content-available flag following the preceding instructions with no message or sound.

What is silent push notification in iOS?

Silent push notifications are simply notifications that mobile app users receive without any pings, alerts, or interruptions to the user. They arrive on the mobile device and sit in the notification tray until read or dismissed.


1 Answers

If there is no badge, no alert, and no sound specified in the dictionary (for the "aps" key) then a default message will not appear and it will be completely silent.

Look again at example 5 in the document you referenced. aps can be empty, and you can specify whatever custom data you would like as they do with the "acme2" key. The "acme2" data is an example of where your server's "special" payload could reside within the JSON payload.

You don't need to tell the server that your app is running. The server can send the special payloads through APNS regardless if your app is running or not, and you will receive that special payload in one of two ways (assuming of course that the push does reach the device... which is not guaranteed):

  1. If your application is in the foreground then iOS will not intercept the notification. You will receive the notification in your app delegate's application:didReceiveRemoteNotification: method (provided that your app delegate does override the method).
  2. If iOS did intercept your push, then when you choose to launch your application in response to the notification then you will need to retrieve the "push dictionary" in your app delegate's application:didFinishLaunchingWithOptions: method as in the following example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self application:application didReceiveRemoteNotification:[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}
like image 157
mamills Avatar answered Oct 08 '22 18:10

mamills