ios - “错误”:发送推送通知时出现“无效注册”
问题描述
我正在使用 FirebasePushNotificationPlugin
in实现 FCM 推送通知Xamarin.Forms
。在 iOS 项目中,AppDelegate
当RegisteredForRemoteNotifications
方法调用deviceToken
生成但当我发送token
Postman 生成的通知时,我收到错误。
{“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 设置
我该如何解决这个问题?
解决方案
我对 Xamarin 不熟悉。但我经常使用 FCM。
我认为你得到了错误的令牌。使用deviceToken
不适用于来自 FCM 的推送通知。我做了一个搜索,也许你必须从
var fcmToken = FirebaseInstanceId.Instance.Token;
推荐阅读
- flutter - 在 Flutter 中根据屏幕宽度更改文本大小
- php - 如何在 WooCommerce 的产品页面中为产品标题添加副标题?
- html - Google Chrome 上的 HTML 不显示我的图片
- reactjs - React - useEffect hook - componentDidMount to useEffect
- c# - 在WPF中托管时如何更改winforms面板的背景颜色?
- php - 使用 PHP [Codeigniter] 从数据库中提取数据到文本文件
- java - 在 Spring Boot 中使用 BCrypt 散列函数而没有所有过度杀伤的安全性?
- c++ - 为什么在下面的代码中返回类型是用于运算符重载的类类型?
- python-3.x - TypeError: unsupported operand type(s) for /: 'list' and 'int' ,同时从 pdf 中提取表格内容
- sql - MYSQL:当条件A满足时从表中选择一个日期;如果日期为空,则从条件 B 中选择日期