Skip to content

Clean up invalid deviceTokens - deleting valid ones as well? #4500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oyvindvol opened this issue Jan 16, 2018 · 11 comments
Closed

Clean up invalid deviceTokens - deleting valid ones as well? #4500

oyvindvol opened this issue Jan 16, 2018 · 11 comments

Comments

@oyvindvol
Copy link

Issue Description

I have set the flag PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS = 1 on Heroku. On some occations my users are reporting that push have stopped working, and when I check their Installation object, the deviceToken is undefined. It has worked for them before.

Is it possible that the clean up flag is also un-setting valid deviceTokens, on some occations?

What happens if I don`t set the flag, will the push sending abort when reaching an invalid deviceToken? Or will it just log, and continue sending pushes to valid ones?

Steps to reproduce

Set up environment with versions as described below. Set the flag PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS=1 on Heroku. Use parse-server for a while, and see that some installation objects may get deviceToken=undefined after some time.

Expected Results

Valid deviceTokens are not un-set.

Actual Outcome

Valid deviceTokens may get un-set.

Environment Setup

  • Server

    • parse-server version: 2.7.1
    • Operating System: Heroku
    • Hardware: Heroku
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Heroku
  • Database

    • MongoDB version: mLab via Heroku
    • Storage engine: mLab via Heroku
    • Hardware: mLab via Heroku
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab via Heroku
@adammlevy
Copy link
Contributor

I had a similar issue, please see this post

@oyvindvol
Copy link
Author

oyvindvol commented Jan 16, 2018 via email

@flovilmart
Copy link
Contributor

@oyvindvol in iOS, usually you can reaquire the device token easily, by registering again for pysh notifications, it is actually recommended to call the registration method on startup to make sure the token is valid.

@oyvindvol
Copy link
Author

oyvindvol commented Jan 16, 2018 via email

@oyvindvol
Copy link
Author

oyvindvol commented Jan 22, 2018

@flovilmart I am testing this now:

  • In parse dashboard I deleted my devicetoken, emptied the column.
  • I run ios app in debug in xcode, didRegisterForRemoteNotificationsWithDeviceToken is getting called.
  • I do like this to update my installation object with the device token (snippet1):
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
  • The device token is not saved to the installation object

Am I doing something wrong here?

Edit:
With this code the deviceToken updates in the database/dashboard (snippet2):

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
//[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation setObject:[self convertDeviceTokenToString:deviceToken] forKey:@"deviceToken"];
[currentInstallation saveInBackground];

I have copied the +(NSString *)convertDeviceTokenToString:(id)deviceToken from PFPushUtilities in the Parse-IOS-SDK code.

Would this be harmful in any way?

Edit 2:
After furter investigation, the first method (snippet1) now updates with the new device token after doing a [currentInstallation fetch] to get the latest from the server (if any changes occurred from the server/db side).

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation fetch];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];

@halavins
Copy link

@oyvindvol why did you close the ticket? Have you found a solution?

@oyvindvol
Copy link
Author

@halvini I got my deviceTokens back when:

  1. Setting the environment variable PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS to 0 on Heroku.
  2. Implementing the code sample in "Edit 2" of my last post (fetching the installation changes from the server before setting the deviceToken again):
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation fetch];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];

@halavins
Copy link

@oyvindvol , oh, I managed to get my back from MongoDB backup.

But did you find a solution for removing the Bad Device Tokens?

@oyvindvol
Copy link
Author

@halvini No.

@chrisbyers
Copy link

I know this is an older thread, but I noticed that the FCM server returns a "NotRegistered" error when sending a push to a device in Do Not Disturb mode. I haven't looked at the parse push code, but if this error results in removing the deviceToken, and you only call register on startup, your app would not receive pushes after DND is turned off on the device.

Also, I think the requirement to call fetch() on the current installation is because the server is removing something (deviceToken) out from under the clients, so the client caches still have a deviceToken and are not marked dirty, so they do not update the server record. This seems messy.

@mtrezza
Copy link
Member

mtrezza commented Jun 24, 2020

FCM server returns a "NotRegistered" error when sending a push to a device in Do Not Disturb mode

@chrisbyers I haven't seen this mentioned in Google Android docs or anywhere else for that matter. It seems pretty counter-intuitive too. Do you have any reference for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants