Device Token Received even after iPhone is not con

2020-06-23 08:32发布

问题:

I was testing my iOS app I found one interesting thing that even my phone is in airplane mode and I have also switched off WIFI, my app is able to receive the the Device Token after registering for push notification.

I have also tried even after removing app and its associated certificate from the iPhone.

but got same results.

How is it possible, any idea ?

thanks in advance.

回答1:

This is from the APNS programming guide :

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.

It implies that if your application is already registered for push notifications, calling the registerForRemoteNotificationTypes doesn't access the APNS server.

The fact that you uninstalled the app doesn't unregister it from APNS. You can prove that to yourself by calling the feedback service immediately after uninstalling the app. You wouldn't get the device token from the feedback service in this case, because the APN service doesn't know you uninstalled the app. Only if you send notifications to the device after uninstalling the app, the APN service will know the app was uninstalled.