admin管理员组文章数量:1206601
In expo SDK36, I target iOS and Android.
I am trying in development the push notification, on Android device, my device have : ExponentPushToken[XYZ]
and my iOS device have ExponentPushToken[ABC]
- Are those generated token unique?
- Are they generated client side ?
- Can I safely add them to my database to identify my devices?
- Will all the release channel (staging/preprod/prod) use the same token for each devices?
In expo SDK36, I target iOS and Android.
I am trying in development the push notification, on Android device, my device have : ExponentPushToken[XYZ]
and my iOS device have ExponentPushToken[ABC]
- Are those generated token unique?
- Are they generated client side ?
- Can I safely add them to my database to identify my devices?
- Will all the release channel (staging/preprod/prod) use the same token for each devices?
3 Answers
Reset to default 13The accepted answer has some out of date information (as of 9/3/21), so here's the latest.
Expo Tokens are generated on the Client when you call Notifications.getExpoPushTokenAsync()
(Notifications is an expo library).
This Token will remain valid EVEN IF the app is updated. Per Expo's documentation:
The ExpoPushToken will remain the same across app upgrades, and ejecting to the bare workflow. On iOS, it will also remain the same even after uninstalling the app and reinstalling (on Android, this results in the push token changing)
You should store this token on your Server DB. They are unique identifiers for sending a push notification to a specific device. From Expo's overview on push notifications:
If push notifications are mail, then the ExpoPushToken is the user's address
Regarding your question about different tokens for different release channels, for Android, there is no difference. For iOS, there will be a different token for Sandbox vs. Production. You should pass an argument to getExpoPushTokenAsync
that indicates that you are in Sandbox
in order to send push notifications with expo, we need to get "expo push token" which is unique for each device. Token is an identifies the device so all the release channel (staging/preprod/prod) use the same token for each device. whenever user logins, we ask for notifications and permissions to get expo push token for the device. So when user logs in "initNotification" function gets fired.
Let's say in a multiplayer game app, a player wants to invite the player1, in the app, we send a request to expo to send a notification to player1. expo first will send you "expo push token".this token is going to be saved into database. when we create a table for our push tokens in DB, this table will have One-To-Many relation with the Players. one player can have "many tokens" because one player can log in using multiple devices and each device will have its unique token. Player instance will hold an array of tokens.
When you send a request to Expo, Expo will return you answer. Either an error message or a "ticket". when we get a successful response from expo, response has ticketId
. if response has an error for the token, we remove the token from the DB becuase for certain type of errors we need to stop sending multiple notifications.
This ticketId
will be stored in the DB. because when we send request to expo and expo sends back its response, even if response is successful it does not mean that notification is received by the device. it just means that the expo received your request to send notification. Expo will then send that notification to Apple or Google and then Apple and Google will send the notification to devices. Using the "ticketId" saved in database, we make a follow up request to expo to check the response that expo received from Apple or Google. if notification was not sent and you try to send notification again, Apple or Google might ban you. that is why we have to remove the tokens from the db. also remove the tickets that handled.
whenever user logs out, we need to remove the token from the db.
All tokens are unique but a new token is generated each time you reinstall the app, so each builds (probably with store updates too) so you have to handle that. You can do something like deleting all tokens at each new build.
Storing tokens in you DB is, as i know, the only way. It's up to you to secure their access.
In Android build, you need a firebase api key to handle notifications. See https://docs.expo.io/push-notifications/using-fcm/
本文标签: javascriptHow does expo push notification token work ExponentPushTokenXYCStack Overflow
版权声明:本文标题:javascript - How does expo push notification token work? ExponentPushToken[XYC] - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738722332a2108821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论