I have a xamarin forms appications that uses https://github.com/CrossGeeks/FirebasePushNotificationPlugin/tree/master library to send notifications. The push notfications are working but I noticed that when I use topics push notfications are only working if I call CrossFirebasePushNotification.Current.Subscribe(topic);
on the constructor of my App.cs public App(){ CrossFirebasePushNotification.Current.Subscribe("general"); }
The issue is I want the topic name to be dynamic i.e the topic should be the name of the user. On my application the name can only be retrieved after the user has logged in. When I put the CrossFirebasePushNotification.Current.Subscribe(topic);
in the Login Content Page View model the notifications don’t work. Is there another way to subscribe to topics besides calling .Subscribe
on the App.cs constructor or on the onstart() method of App.cs. I tried using MessagingCenter
but that didn’t work. Below is the code on App.cs
MessagingCenter.Subscribe <string>.(this,"SubcribeToFcm", (topic) => {
CrossFirebasePushNotification.Current.Subscribe(topic);
});`
Below is the code on my LoginViewModel.
var topic = User.Name.ToLower();
MessagingCenter.Send(this, "SubcribeToFcm", topic);