7

When a user installs my app I register his registration ID (android) or device token (iOS) and send push notifications that work fine. But now I want to remove the user from the server when the app is uninstalled.

How can I accomplish this in Phonegap: get an event after which i can unregister the user registration id (android) or device token (ios)?

Note: I am using PushPlugin

Ajoy
  • 1,838
  • 3
  • 30
  • 57
ahsanali
  • 83
  • 1
  • 5

1 Answers1

8

AFAIK, you cannot know when your app is uninstalled.

For your android app, observe the response GCM returns when you send a notification. If it sends a NotRegistered message, you can remove that id from your server. Read how unregistration works

For iOS : read this Question and its answer on SO

Community
  • 1
  • 1
Ajoy
  • 1,838
  • 3
  • 30
  • 57
  • thanks ajoy, i hadn't tested it yet, will do it soon and will update you too on this page, thanks alot for reply – ahsanali Apr 03 '15 at 14:53
  • @Ajoy but what if the owner of the device reinstall the app, he will still get a duplicate notifications for every subscription. I'm using aws sns service with gcm, I don't know how to prevent this problem. In the aws sns dashboard I have like 13 subscriptions, but actually there is only 2 devices where the app is installed – Nourdine Alouane Nov 08 '16 at 15:54
  • @NourdineAlouane When you get the `NotRegsitered` message, you are supposed to remove it from your list. If the user reinstalls the app, and is re-registered, every GCM response will have `canonical_id` in the response. Use it to update the registration id for that user. – Ajoy Nov 10 '16 at 15:05
  • Also see this link on handling [GCM responses](https://developers.google.com/cloud-messaging/http#response). – Ajoy Nov 10 '16 at 15:06
  • @Ajoy well, I actually contacted aws support for this issue, they reported that this problem is handled by aws sns & google gcm implicitly, it means that I should not change the code, it's the normal behavior, after 3 days, the duplicate notifications simply stopped. I have tested a bunch of solutions, I even created a special aws sns subscribers DB in a server & blocked any duplicate subscription when the device has already registred. But the truth is that, GCM actually detect app uninstall, and tells aws sns about token update, but it takes up to 4 days, perhaps it depends on your country – Nourdine Alouane Nov 11 '16 at 10:50