firebase - 为什么我的 Xamarin.iOS 应用程序没有收到来自 Google Firebase 的推送通知?
问题描述
我正在尝试使用 Google Firebase 向我的 Xamarin Forms App for iOS 发送推送通知...我没有收到通知
要发送通知,我只需将令牌从输出窗口中复制出来,将我的应用程序放在后台,然后将令牌粘贴到 Firebase 通知构建器中。
我收到了 FCM 令牌,所以我的应用肯定在与 Firebase 对话。
到目前为止,我已经尝试过:
撤销我的苹果开发者证书和配置文件,然后制作新的。
我创建了一个新的 Firebase 项目并包含了新的 GoogleService-Info.plist 文件(构建操作-> BundleResource)。我认为这不会做任何事情
在我的 info.plist 的后台模式中启用远程通知
任何建议表示赞赏!
public override bool FinishedLaunching(UIApplication app, NSDictionary
options)
{
global::Xamarin.Forms.Forms.Init();
UIApplication.SharedApplication.RegisterForRemoteNotifications();
Firebase.Core.App.Configure();
_connection = DependencyService.Get<ISQLiteDb>().GetConnection();
LoadApplication(application: new V5KitchenApp.App());
// Register your app for remote notifications.
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// iOS 10 or later
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
Console.WriteLine(granted);
var token = Messaging.SharedInstance.FcmToken ?? "";
Console.WriteLine($"FCM token: {token}");
SendTokenToServer(token);
});
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
// For iOS 10 data message (sent via FCM)
Messaging.SharedInstance.Delegate = this;
}
else
{
// iOS 9 or before
var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}
return base.FinishedLaunching(app, options);
}
这是我覆盖 DidReceiveRemoteNotification 的方法
public override void DidReceiveRemoteNotification(
UIApplication application,
NSDictionary userInfo,
Action<UIBackgroundFetchResult> completionHandler)
{
PresentNotification(userInfo);
completionHandler(UIBackgroundFetchResult.NewData);
}
这就是我呈现通知的方式
void PresentNotification(NSDictionary dict)
{
NSDictionary aps = dict.ObjectForKey(new NSString("aps")) as NSDictionary;
var msg = string.Empty;
if (aps.ContainsKey(new NSString("alert")))
{
msg = (aps[new NSString("alert")] as NSString).ToString();
}
if (string.IsNullOrEmpty(msg))
{
msg = "(unable to parse)";
}
MessagingCenter.Send<object, string>(this, App.NotificationReceivedKey, msg);
}
我正在使用 Xamarin.Firebase.iOS.CloudMessaging v3.1.2 Xamarin.Firebase.iOS.Core v5.1.8 Xamarin.Firebase.iOS.InstanceID v2.0.0
解决方案
问题是我使用了下一个版本的 Firebase 版本:
Xamarin.Firebase.iOS.InstanceID 2.0
Xamarin.Firebase.iOS.CloudMessaging 2.0
Xamarin.Firebase.iOS.Core 4.0.3
Xamarin.Firebase.iOS.Analtics 4.0.2
推荐阅读
- android - 示例 google 广告未在 android 中显示(移动广告 SDK)
- r - 将带有斜体的轴标签与 R rgl 包中的轴平行
- javascript - 如何使用 onEdit 触发器修改/更新谷歌日历事件?
- php - 如何从 echo 获取 PHP 输出中的换行符?
- spring-boot - StreamsException:无法初始化状态,如果 Kafka Streams 的多个实例在同一个状态目录中运行,可能会发生这种情况
- python - subprocess.run 调用可执行文件失败
- css - 内容 div 位于导航栏上方
- javascript - 更改推荐链接
- javascript - 在excel桌面加载项(webview 1)中下载csv数据
- r - 为什么在这种情况下 ctree 只返回一个终端节点?