首页 > 解决方案 > “错误”:发送推送通知时出现“无效注册”

问题描述

我正在使用 FirebasePushNotificationPluginin实现 FCM 推送通知Xamarin.Forms。在 iOS 项目中,AppDelegateRegisteredForRemoteNotifications方法调用deviceToken生成但当我发送tokenPostman 生成的通知时,我收到错误。

{“multicast_id”:8631208504861228784,“成功”:0,“失败”:1,“canonical_ids”:0,“结果”:[{“错误”:“无效注册”}]}

这是我AppDelegate这里得到的代码:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());

    FirebasePushNotificationManager.Initialize(options, new NotificationUserCategory[]
    {
        new NotificationUserCategory("message",new List<NotificationUserAction> {
            new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground)
        }),
        new NotificationUserCategory("request",new List<NotificationUserAction> {
            new NotificationUserAction("Accept","Accept"),
            new NotificationUserAction("Reject","Reject",NotificationActionType.Destructive)
        })
    });

    return base.FinishedLaunching(app, options);
}

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
    FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
    Console.WriteLine("Token- - - :  "+deviceToken);
}

public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
    FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);
}

public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
    FirebasePushNotificationManager.DidReceiveMessage(userInfo);
    System.Console.WriteLine(userInfo);
    completionHandler(UIBackgroundFetchResult.NewData);
}

object发送示例通知时 Postman 中的数据

{ 
 "to":"79f64b43339859a329a935f7a3e417ecc1599fbb5d6935afbooa3b4291c07fa7", 
 "notification" : {
 "body" : "New task",
 "content_available" : true,
 "priority" : "high",
 "color":"Page1",
 "title":"Announcement"
 },
 "data" : {
 "color":"Page1",
 "title":"title",
 "content_available" : true,
 "body" : "New Announcement ad"

}
}

邮递员的身体

在此处输入图像描述

这些是 Visual Studio 中的 Provisioning Profiles 设置

在此处输入图像描述

我该如何解决这个问题?

标签: iosxamarinxamarin.formsxamarin.iosfirebase-cloud-messaging

解决方案


我对 Xamarin 不熟悉。但我经常使用 FCM。

我认为你得到了错误的令牌。使用deviceToken不适用于来自 FCM 的推送通知。我做了一个搜索,也许你必须从

var fcmToken = FirebaseInstanceId.Instance.Token;

更多详细信息: https ://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=macos


推荐阅读