简体   繁体   中英

Problem with Firebase registration token and notifications

I have a couple of questions about firebase registration token and firebase notifications, so lets start

  1. I generate registration token everytime user tries to sign in to my app and I save it to user document in firestore database. My question is: What will happen if I log in on another phone (using my friends phone) also (token is saved in database), then log out and before I log in on my phone I get notification. Will that notification be sent to my friends phone or mine?

  2. If it is going to be sent to my friends phone, how can I ensure that notifications always come to phone where Im currently signed in and is that possible at all?

  3. What is the best approach to save tokens and send notifications to phone?

I'm currently a little bit confused about all this.

  1. If the last token you stored is the one on your friend's phone, and you send the notification to the stored token, then it will be sent to the friend's phone.

  2. Since you're not signed in on your own phone yet, and you only store one token per user, you can't receive the notification on your own phone.

  3. It sounds like you:

    • Have an app that you expect users to sign in to on multiple devices
    • You want them to only receive notifications when they're signed in on a device

    In that scenario I'd recommend wiping the token from the app and or the database when the user signs out. The flow would look something like this:

    1. Wipe the token from the database
    2. Call deleteInstanceId to release the token in the app instance
    3. Sign the user out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM