FCM Message not Received on iOS App when sent to a topic

Viewed 124

I want to send notifications with FCM to an iOS App. It works fine when I send it to the token, but it doesn't work when I send it to a topic. I tried subscribing the App to the topics using this:

string[] topics = { "all", "test" };
CrossFirebasePushNotification.Current.Subscribe(topics);

(This is using the Plugin.FirebasePushNotification) or using this:

string[] tokens = { e.Token };
FirebaseMessaging.DefaultInstance.SubscribeToTopicAsync(tokens, "test");
FirebaseMessaging.DefaultInstance.SubscribeToTopicAsync(tokens, "all");

(This is using FirebaseAdmin) It's both in the App.xaml.cs, the first one beeing under InitializeComponent(); and the second one beeing in OnTokenRefresh. It works fine on android, but not on iOS. Keep in mind, that e.Token is the Token. I even tried to subscribe in the AppDelegate.cs, but it didn't work there either. I think it could be because it tries to subscribe before I even said "Yes" on the device so it can send me Notifications. I'm using an iPhone SE with iOS 15.3. Thanks for your help!

1 Answers

I figured it out. In the AppDelegate.cs you can override the RegisteredForRemoteNotifications and you can just subscribe there. This means, it will subscribe if the user grants the permission to send remote notifications. After that it worked perfectly.

Related