iosruby-on-railspush-notificationapple-push-notifications

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


Solution

  • Seems to be a possible solution from apple developer forum:

    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.