Skip to content
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

Installation deviceToken is undefined #1224

Closed
adammlevy opened this issue Dec 20, 2017 · 16 comments
Closed

Installation deviceToken is undefined #1224

adammlevy opened this issue Dec 20, 2017 · 16 comments
Labels
type:question Support or code-level question

Comments

@adammlevy
Copy link
Contributor

I have noticed that after a period of time receiving push notifications on my device I will suddenly stop receiving push notifications on that device. One thing I have noticed is that the deviceToken is set to (undefined) in the dashboard as seen in the included screenshot. How is it possible that the deviceToken goes from some value to undefined.

screen shot 2017-12-20 at 12 13 03 am

@montymxb
Copy link

It should not. Can you provide more details regarding the circumstances and number of times you have seen this happen?

@adammlevy
Copy link
Contributor Author

I see other users in the dashboard which have subscribed to push notifications and do not have a device token either so it's not just happening on my device. Deleting the app and reinstalling will cause the app to create a new Installation with a defined deviceToken but after around 1-2 weeks the deviceToken is back to nil.

I thought maybe the deviceToken coming back from didRegisterForRemoteNotifications was nil so I first check if the deviceToken has data before setting it to the Installation

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    if (deviceToken) {
         [currentInstallation setDeviceTokenFromData:deviceToken];
         [currentInstallation saveInBackground];
    }
}

The docs recommend registering for remote notifications when applicationDidFinishLaunching is called however since I don't want the notification prompt to come up on first launch I am only registering notifications when the user begins subscribing to channels.

@montymxb
Copy link

montymxb commented Dec 21, 2017

So in your this only happening for iOS related devices? By chance do you also have any android installs as well that are not doing this? If so that helps narrow it down to something more specifically regarding just this sdk.

It should be noted that the server-side requirement is either a deviceToken or an installationId. If you need to guard against strange behavior with null deviceTokens you can always setup a beforeSave hook to provide a check to require a deviceToken.

Parse.Cloud.beforeSave('_Installation', function(request, response) {
    if(!request.object.get('deviceToken')) {
      // prevent from saving
      // note the bad installation
      // maybe do something else to help track it with details...
      response.error('installation blocked from being saved! Device token missing!');
    } else {
      response.success();
    }
});

@brianyyz
Copy link

Any chance you're using the configuration parameter PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS

when you start your parse server ?

@adammlevy
Copy link
Contributor Author

@brianyyz am running parse server on Heroku and have PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS set to 1 in config vars.

@adammlevy
Copy link
Contributor Author

@montymxb I don't have push enabled for Android (yet) so would have no way of knowing if it's just an iOS issue. I'll try adding the beforeSave logic and see if that fixes the issue. Thanks!

@flovilmart
Copy link
Contributor

So if you have that feature flag enabled, this is actually the expected behavior. Remove the feature flag if you don’t want to cleanup the invalid device tokens.

@adammlevy
Copy link
Contributor Author

adammlevy commented Dec 22, 2017

@flovilmart According to this post you said this should be the default behavior so won't I experience the same issue even without the flag?

@flovilmart
Copy link
Contributor

It’s still feature flagged, as of today, so removing the flag would be ok if you don’t need the feature

@adammlevy
Copy link
Contributor Author

How does parse-server decide a token is invalid? If I remove this feature then won't my installation be filled with invalid device tokens?

@flovilmart
Copy link
Contributor

flovilmart commented Dec 22, 2017

The server removed the invalid tokens based on the response from the push adapter. APNS or GCM return explicit responses when trying to send a push to a token that is no longer valid. Depending on your use cases, you may wanna keep the feature or not.

this is where the decision is made: https://github.com/parse-community/parse-server/blob/c1a734714361ba65e32c9781d3c8f924f1187df5/src/StatusHandler.js#L230

@adammlevy
Copy link
Contributor Author

I will try without this feature. Thanks.

@halavins
Copy link

I can confirm that setting PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS to 1 actually clears VALID deviceTokens for iOS users.

Setting this parameter is actually dangerous for your service! 30% of our iOS users lost the ability to receive push notifications after we set the variable to 1.

@flovilmart
Copy link
Contributor

@halvini, I’m curious why it would clean those valid tokens when APNS returns clearly an error for the particular token

@halavins
Copy link

halavins commented Dec 27, 2017

@flovilmart, I'm curious too.

@adammlevy said: "Deleting the app and reinstalling will cause the app to create a new Installation with a defined deviceToken but after around 1-2 weeks the deviceToken is back to nil."

We had exactly the same issue with the users who had valid deviceTokens. When we switched the PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS to 1, iOS users started massively reporting that they don't get any Push Notifications. Android users didn't experience such problems though.

@halavins
Copy link

@flovilmart any ideas how to resolve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

6 participants