ios push notification not received after getting out of airplane mode

I'm sending a push notification using Noticed Gem during the night when my phone is in airplane mode. When I wake up and disable the airplane mode, I don't get the push notification.

These are the settings:

`  def ios_format(apn)
      apn.custom_payload = { universal_link: url }
      apn.alert = { title: title(recipient), body: message(recipient) }
      apn.sound = 'default'
      apn.priority = '10' # Send immediately, bypassing the
  end
`

default expiration is supposed to be 30 days.

How can I debug/fix the problem? (with noticed gem)

I checked Apple consoleKIT, and I don't see discarded notifications.

Thanks

Answered by Engineer in 788839022

The reason you are not getting a notification when the device comes back online is, by that time, the notification you sent to it is lost. This is due to your push server seemingly having multiple push tokens for the same device.

Let me explain: APNs stores undelivered notifications until they expire -OR- until another notification is sent to the same device for the same app. In your case you have sent a number of notifications to some other tokens, which happen to be older unused tokens (probably belonging to the older versions of the app) which are destined for the same device.

The problem arises, because APNs stores the subsequent notifications overwriting the one you sent at 4:09, the 4:09 notification is lost. When the device comes back online, APNs tries to send the last notification over, but because you have used a token that is no longer valid, that notification which gets sent is never received.

While you may get an error (410) from APNs when using tokens no longer in use, if and when a token will start triggering this error is is randomized to protect the user's privacy. In the meantime, you will want to clean up your token database to ensure there aren't multiple tokens per device or user. Under some circumstances, for example if you delete and app and install a new version, you will get assigned a new token. You would want to make sure that the existing token for that device is removed from your list of tokens.

What the settings are for a 3rd party tool does not necessarily mean the actual notification request is as it should be.

If you have the actual HTTP/2 request this tool is sending out, please share that. Also would help to know some more information:

  • exact time and date (including time zone) of getting ON Airplane Mode
  • exact time and date (including time zone) of the push request sent
  • exact time and date (including time zone) of getting OFF Airplane Mode
  • your push topic (apns-topic header value)
  • your app’s Bundle ID
  • the device token
  • any logging you have from the server side that shows the interaction with it and APNs.
Accepted Answer

The reason you are not getting a notification when the device comes back online is, by that time, the notification you sent to it is lost. This is due to your push server seemingly having multiple push tokens for the same device.

Let me explain: APNs stores undelivered notifications until they expire -OR- until another notification is sent to the same device for the same app. In your case you have sent a number of notifications to some other tokens, which happen to be older unused tokens (probably belonging to the older versions of the app) which are destined for the same device.

The problem arises, because APNs stores the subsequent notifications overwriting the one you sent at 4:09, the 4:09 notification is lost. When the device comes back online, APNs tries to send the last notification over, but because you have used a token that is no longer valid, that notification which gets sent is never received.

While you may get an error (410) from APNs when using tokens no longer in use, if and when a token will start triggering this error is is randomized to protect the user's privacy. In the meantime, you will want to clean up your token database to ensure there aren't multiple tokens per device or user. Under some circumstances, for example if you delete and app and install a new version, you will get assigned a new token. You would want to make sure that the existing token for that device is removed from your list of tokens.

APNs may start returning an “error” (410 status) for tokens if it has determined that a particular token is no longer in use. To make this determination, the device itself must report back to APNs that it is no longer accepting notifications for the app. This happens only if an app has been deleted on a device that is otherwise in use, and then a notification is sent to the app once, then the token will be marked as "not in use".

Even if and when APNs becomes aware of the token no longer being in use, to avoid developers from detecting and tracking user behavior around installations and uninstallations, APNs will start returning a 410 status for these tokens on a fuzzy schedule. This schedule is not documented, and can change at any time. This is for protecting the users’ privacy, and is by design.

You will find many edge cases where the token may no longer be in use, but you will always get a success status for it. How to manage your tokens (whether per person or per device) and cleanup unused ones will be up to your business needs and use case.

ios push notification not received after getting out of airplane mode
 
 
Q