0

I have an application in iOS that receives push notifications through GCM (Google Cloud Messaging) and APNS . These notifications contain some data that has to be processed before showing anything to the user.

After data processing, I generate a local notification with proper information to the user.

I see this behaviour:

  • With the app in foreground I only see the local notification.
  • With the app in background I see both notifications, remote and local.
  • With the app not even running, no notification is shown.

Can I show only my local notification after processing some data? (at least when the app is in background)

I have read about using content-available property as documented here, but the behaviour is almost the same.

logoff
  • 3,347
  • 5
  • 41
  • 58
  • 1
    Yes, you can. Look here: http://stackoverflow.com/questions/20741618/didreceiveremotenotificationfetchcompletionhandler-not-being-called-when-app-is – Dmytro Shvetsov Sep 07 '16 at 07:55

1 Answers1

0

Finally I get the solution (thanks to @DmytroShvecov for the pointer).

It is necessary to follow the official documentation here and follow these steps in the server:

  • Include inside aps keys alert, badge and sound but with blank value.
  • Include content-available key with 1 as value (if you want your notifications to be processed in background without interaction of the user.
  • Include any acme key to be treated as custom payload with your data.

This is an example of everything working together:

{
  "aps": {
    "alert": "",
    "badge" : "",
    "sound":"",
    "content-available": 1
  },
  "acme": {
    "what": "ever",
    "you": "want"
  }
}
logoff
  • 3,347
  • 5
  • 41
  • 58