Hi!
First off, absolutely love the work you’ve done with Expo! Helped me a lot along the way!
Now, I have have an issue I haven’t been able to figure out or found enough information about. It has to do with push notifications and the “DeviceNotRegistered” error. I’ll explain two scenarios I’ve used to handle notification tokens for the user and then explain what I’ve experienced.
Scenario 1
A) On app launch, the app asks for notification permissions. If “granted”, generates token and saves to my backend and associates it with the user. It also saves the token to the SecureStore.
B) The app first checks the SecureStore for a push token. If present, doesn’t generate a new token but continues (the token is already associated with the user in my backend)
I implemented the above solution to not generate tokens on each app launch and not making “unnecessary” calls to my backend for saving it. However, as I read your documentation further I noticed that the tokens can differ if the application is reinstalled, but the SecureStore token value persist so there could most probably become a mismatch here so that the token in SecureStore is no longer a valid one and a new token should have been created anew.
Scenario 2
On app launch, the app checks permissions and if granted generates token and sends it to my backend for saving. This is now happening on each application launch to ensure a “fresh” token is always held in my backend. Nothing gets handled trough the SecureStore as a mentioned in “Scenario 1”.
Conclusion / problem
I have used the expo client on iPhone without any problems with the push token. However, we recently started builds with expo for trying out the APK natively on Android phones. And they are having troubles with their tokens not being valid. I’ve checked the token generated for these devices and they are the same when running the app trough Expo client and when running the app from the APK built.
I’ve followed the guide on https://docs.expo.io/versions/latest/guides/push-notifications.html (awesome guides btw!) and all works as intended as far as asking permissions and generating tokens, but the tokens have been “corrupted” somehow.
So I am looking for some best practice and if I’m doing something wrong in either of the scenarios a described above. Since my only conclusion as to why this has started happening is because some “mismatch” between tokens when running the native APK on Android or running the application through expo client. This may be a “non issue” on app release further but I can’t know for sure.
The questions I’ve been asking myself is:
- Can I “over use” the call to “getExpoPushTokenAsync()”? In scneario 1 this wasn’t the case but now I use the method on every app launch to ensure fresh and valid token.
- Are there any difference in how and what token gets generated when running through the client and running native apk?
- How can I ensure a valid token is saved to my backend on application launch, I use the application on my phones in development now in three different ways: a) exp start --lan b) Through account QR (builds on my expo account) c) Downloading the APK and installing it on Android phone.
I’m posting because I’ve tried to find these answers here and on other places but can’t find this particular problem. Happy to be pointed in the right direction, have a missed it.
Thank you!
/Johan