In which mobile platforms the “push token” is not permanent?

前端 未结 3 1622
挽巷
挽巷 2021-02-10 22:27

We all know that in order to use the push notifications functionality in any mobile platform we need a unique identifier called \"push token\".

The developer needs someh

3条回答
  •  野的像风
    2021-02-10 22:46

    The Token is never permanent.

    In iOS, the Device Token is the same for all the applications on the device. In practice, it stays the same until you upgrade your iOS version or restore your device from a backup. In theory Apple say it may change anytime, so you should handle this case.

    By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device. If a user restores a backup to a device or computer other than the one that the backup was created for (for example, the user migrates data to a new device or computer), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or computer, or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. If your application has previously registered, calling registerForRemoteNotificationTypes: results in the operating system passing the device token to the delegate immediately without incurring additional overhead.

    In Android, the Registration ID is different for each application on the same device. It sometimes changes when you un-register your app from GCM and then re-register it. However, the old Registration ID often works for sending GCM messages to the app (you would get a canonical registration ID in the response in this case, asking you to use the newest Registration ID). That said, Google also claim the registration ID may change any time, so you should handle this case.

    Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.

    The registration ID lasts until the Android application explicitly unregisters itself, or until Google refreshes the registration ID for your Android application.

    In Windows Phone, I'm not sure how often does the Notification Channel URI changes in practice, but Microsoft also claim it may change anytime.

    All apps should register for the ChannelUriUpdated event in case the push notification URI changes. Even if you already have a channel opened, you should register for the ChannelUriUpdated event in case the URI changes.

    To summarize, you should always treat the Token as if it may change any time you restart your application.

提交回复
热议问题