我设置了一个Xamarin表单iOS应用程序,可以使用firebase cloud Messaging使用Xamarin.firebase.ios.cloudmessaging v3.1.2
,以用于推送通知我可以在DidReceiveRegistrationToken
方法中正确获取FCM令牌,然后拨打其余端点https://fcm.googleapis.com/fcm/send
,并且通知将按预期发送。
问题是,只要有未手动的例外或当前线程被手动杀死并且我的应用程序崩溃时,FCM令牌就会被放置,并且相同的API呼叫将导致"error": "NotRegistered"
响应。
那时,我所能做的就是卸载并重新安装该应用程序以获得新的FCM令牌,并且事情再次按预期工作。
这是我的appdelegate.cs
中的主要壁炉设置代码 public void RegisterFirebaseNotifications()
{
UNUserNotificationCenter.Current.Delegate = this;
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
{
if (error != null)
{
Log.Error("Error occurred getting authorization from user app");
Log.Error(error.Description);
}
});
UIApplication.SharedApplication.RegisterForRemoteNotifications();
Messaging.SharedInstance.Delegate = this;
// To connect with FCM. FCM manages the connection, closing it
// when your app goes into the background and reopening it
// whenever the app is foregrounded.
Messaging.SharedInstance.ShouldEstablishDirectChannel = true;
}
#region IMessagingDelegate
[Export("messaging:didReceiveRegistrationToken:")]
public void DidReceiveRegistrationToken(Messaging messaging, string fcmToken)
{
Utils.Settings.FirebaseNotificationToken = fcmToken;
}
[Export("messaging:didReceiveMessage:")]
public void DidReceiveMessage(Messaging messaging, RemoteMessage remoteMessage)
{
HandleMessage(remoteMessage.AppData);
LogInformation(nameof(DidReceiveMessage), remoteMessage.AppData);
}
#endregion
我正在使用的firebase云消息的版本存在问题。我在GitHub上发现了这个问题,建议将降级的版本降级到我的问题。