24

I've encountered an unusual scenario where a user is continuing to receive notifications when my app has been deleted and then reinstalled. The scenario is as follows:

  • user installs the app from the appstore
  • user logs onto our app and we register them for notifications
  • user deletes the app from their device
  • user reinstalls the app from the appstore
  • user receives a notification even though they have not started the app up yet, logged in, etc

My understanding of the APNs architecture was that once your app is deleted from your device, it is de-registered from APNs by the OS itself. A reinstall of the app would not re-enable notifications until you called "registerForRemoteNotificationTypes" -- so if a note was sent to the device using the old token, APNs would not deliver it since the above method has not been called.

Is that not accurate?

Eran
  • 387,369
  • 54
  • 702
  • 768
Vik
  • 1,301
  • 4
  • 16
  • 29

2 Answers2

23

The token remains the same. It's even the same for all applications on the device. It only changes when you change the OS version. However, that still doesn't explain the strange behavior you encountered.

I believe that only after Apple identifies that the application has been uninstalled from the device (which usually happens when you send a notification to the app on a specific device after the device uninstalled it) it un-registers the app. If no notifications were sent to the app on the device that uninstalled the app between the time of uninstall and the time of the new installation, Apple don't know the device uninstalled the app, and therefore it is still registered for APNS.

The behavior of the feedback service supports my theory - if you uninstall the app and call the feedback service, you won't get the device token of the device that uninstalled the app. Only after you try to send a notification to that device, Apple will detect the uninstall and return that device token in the feedback service.

One last thing I should add - if the uninstalled app is the last one on the device that was registered for push notifications, the APN service will never know that the app was uninstalled, and therefore it will still be registered for APN after being re-installed.

Eran
  • 387,369
  • 54
  • 702
  • 768
  • Yeah, after some testing I suspect this is the case. I guess this suggests that you check the feedback service multiple times a day to remove device tokens. Not sure I follow what you mean in the last paragraph. – Vik Feb 13 '13 at 17:18
  • @Vjayus First of all, checking the feedback service wouldn't solve your problem. If you don't send a notification to the device while the App is uninstalled, the APN service won't know it's uninstalled, and calling the feedback service wouldn't change that. You don't have to call the feedback service multiple times a day, unless you send every day multiple messages to the same devices. – Eran Feb 13 '13 at 17:45
  • @Vjayus My last paragraph refers to something Apple state in the APN documentation. If after uninstalling the application your device has no installed applications that are registered to Push Notifications, the APN service won't ever detect that your app was uninstalled from the device. This is not very likely to happen, since many popular applications register to push notifications. – Eran Feb 13 '13 at 17:53
  • In my experience, Token is not the same for different app in your IOS device. And I want to ask, when I uninstall app and then send a push to the device, how long can I get the feedback from the feedback service?It seems I always get the empty feedback. – yunfan Jun 10 '15 at 03:00
  • 1
    @yunfan Yes, this answer is a bit outdated. Since iOS7, each app has a different device token on the same device. As for the Feedback, when I last tested it, sending two push notifications to a device token of a device that uninstalled the app was enough in order to get that device token from the Feedback service. Note that once you get a device token from the feedback service, the next call to the Feedback service won't return that device token again (unless you send more notifications to that device token between the calls to the feedback service). – Eran Jun 10 '15 at 10:48
  • 1
    @Eran But in this case how to de-reegister previous token from Server. In my case I'm using 3rd party XMPP server that communicate with APNS and APNS send message to device. But if user uninstall app without de-register, XMPP server will never come to know about APNS-de-register and it remain lineup. How to handle such scenario. – CoDe Mar 08 '17 at 10:04
  • 3
    This answer is outdated now. I have tested using iOS 11 and XCode 9.2, that every time I'd install production build on iPhone, a new Device token is generated for application if user allow APNS to send push notification, That's mean your notification will not be received using old device token. – s.zainulabideen Jan 12 '18 at 05:18
11

When you delete the app, the OS doesn't "de-register" it from APNS. You have to send a notification to a device that has deleted the app in order to "de-register" it. This may take a few tries from APNS until it figures out the app has been deleted.

GabCas
  • 778
  • 8
  • 28