gpt4 book ai didi

ios - "error": "InvalidRegistration" while sending push notifications

转载 作者:可可西里 更新时间:2023-11-01 03:19:00 30 4
gpt4 key购买 nike

我正在使用 FirebasePushNotificationPlugin 实现 FCM 推送通知在 Xamarin.Forms 中。在 iOS 项目中,在 AppDelegate 中,当 RegisteredForRemoteNotifications 方法调用 deviceToken 生成时,但是当我发送生成的 token 通知时 postman 我收到错误消息。

{ "multicast_id": 8631208504861228784, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "InvalidRegistration" } ] }

这是我在 AppDelegate 上的代码,来自 here :

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);
}

发送示例通知时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"

}
}

postman body

enter image description here

这些是来自 Visual Studio 的配置文件设置

enter image description here

我该如何解决这个问题?

最佳答案

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

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

var fcmToken = FirebaseInstanceId.Instance.Token;

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

关于ios - "error": "InvalidRegistration" while sending push notifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55594820/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com