Search code examples
iosapple-push-notifications

Correct way to send push to wake an app w/an alert banner (and sound)


I'm working on an app that doesn't wake when receiving an alert with content available set to 1.

I understand the newer API (UserNotifications) dictates a paradigm where a background alert should be sent, data received and a new local notification sent to the user, however we're not in a position to currently refactor the payloads sent to APNS. (though we could be if needed)

Assuming our payload is based off the documented payload here (https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification)

{
   “aps” : {
      “alert” : {
         “title” : “Game Request”,
         “subtitle” : “Five Card Draw”
         “body” : “Bob wants to play poker”,
      },
      "content-available": 1 // ** We add this here, to alert the user & wake the app **
      “category” : “GAME_INVITATION”
   },
   “gameID” : “12345678”
}

Note, We further add content-available: 1 to this payload. In our post to APNS we specify the alert type.

Previously, iOS would alert the user of the notification and wake the app if it was in the background. That behavior seems to have stopped as now apps are no longer waking in the background (but alerts still come through).

As we have active users and are always in a time crunch it would awesome to find the quickest way to get the app back up and running in the background and alerting.


Solution

  • Please remove the 'apns-push-type' on the post to apns.

    This will revert to the previous functionality where it shows the alert and also wakes up the app. I dont guarantee any time period for how long this will continue to work because this is a required field going forward. So make sure your backend modifies their payload to apns as soon as the front end supports the new architecture.

    :) Happy coding Fred!