Clean up invalid deviceTokens - deleting valid ones as well?
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
I had a similar issue, please see this post
@adammlevy Thanks. So the solution is removing the clean-up flag? And the ones who have lost their deviceToken already need to re-install?
@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.
@flovilmart Yes, I am calling it on startup. That’s why I found it strange that the affected installations did not get a new deviceToken on startup. They remain undefined..
@flovilmart I am testing this now:
- In parse dashboard I deleted my devicetoken, emptied the column.
- I run ios app in debug in xcode,
didRegisterForRemoteNotificationsWithDeviceTokenis 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];
@oyvindvol why did you close the ticket? Have you found a solution?
@halvini I got my deviceTokens back when:
- Setting the environment variable
PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONSto0on Heroku. - 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];
@oyvindvol , oh, I managed to get my back from MongoDB backup.
But did you find a solution for removing the Bad Device Tokens?
@halvini No.
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.
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?