Detect uninstall event in phonegap app
Asked Answered
W

1

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

Wont answered 28/3, 2015 at 13:19 Comment(0)
B
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

Bimolecular answered 3/4, 2015 at 14:45 Comment(5)
thanks ajoy, i hadn't tested it yet, will do it soon and will update you too on this page, thanks alot for replyWont
@Bimolecular 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 installedArtist
@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.Bimolecular
Also see this link on handling GCM responses.Bimolecular
@Bimolecular 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 countryArtist

© 2022 - 2024 — McMap. All rights reserved.