I implemented push notifications with pubnub. I have following issue with it, when I uninstall application and right after that I install it again, application isreceiving push notification without registration to gcm. I guess it is because unregister to gcm is not called on uninstal, and gcm server is still having device registration id on second instalation.
-
*unregister to gcm is not called on uninstall* - your app code is not executed when the app is deleted/uninstalled. Are you getting a new GCM registration token when the app is reinstalled? If so, the old GCM token should be invalidated by GCM service and PubNub will get that *invalid token* notification and remove channels associated with that token. On iOS, you can use key chain to persist across installations of the app - not sure Android has similar mechanism but I will ask. – Craig Conover Jun 15 '16 at 19:18
3 Answers
I don't think it's possible, give a look here
But you could make some logic to avoid this unexpected behaviour if in your app users must be logged in. When you send a push notification from server, you should send a parameter to identify user (for example a userId). Then when the app receive notification, you should compare the received value with the local value (this local value will be lost with uninstall) and if they don't match, stop your notification builder showing notification.
If don't have nothing to identify user locally, you could set a boolean in SharedPreferences to true when registering for push. If this boolean is false don't show notification.
-
1Great alternative, doing doble check on client side before displaying the notification. – htafoya Jul 23 '17 at 17:43
You can create 1 global variable let's say private int nStatus=0 and give it value of 1 in SharedData and then on starting app you can check does it have value of 1 or 0 if it's 1 create notification else don't because when you delete app you delete SharedData also
At the start of your app, just do registration again at the first point. So the last one will be overwritten, and gcm will not deliver push to last gcm id.
- 3,546
- 1
- 24
- 31