简体   繁体   中英

Best way to add new tag to existing registered device (FCM, Xamarin.Forms, c#)

Sorry ahead of time as I'm at work so I don't have all my code in front of me that I could post here.

I'm wanting to figure out the best way to add a new tag to an existing registered device in FCM. Basically I have a Xamarin.Forms app with push notifications implemented. The question was brought up about what happens if a user logs into the app from a different device. How would you add a new tag (or the tag associated with that user) to the device so they can receive the notifications that are associated with them while they're logged in?

I started looking at some of the rest API's in the documentation (again...sorry I don't have the link to it) and it looks like there's one API where its "create/update device registration" and it basically takes a tag(s) and the gcm registration id (I think).

My thought was that I could pull the already registered device id and use that to update the registration with a new tag using the Rest API. What does the c# code look like to pull the existing registration id?

I've been trying to use the FirebaseInstanceId.GetInstance().GetInstanceId().GetToken (pseudo from memory) but I'm not sure I'm doing it correctly.

Is this the correct approach?

I believe I found the answer to my own question in the form of Xamarin.Forms.Application.Current.Properties found here .

I tested with the approach of storing the gcm registered id (token) in the properties dictionary after the initial token creation. I then closed the app, re-opened it and verified that the token value persisted and I was able to retrieve the value so I could then use it in the API calls.

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