我正在尝试使用 Google Firebase 向我的 iOS 版 Xamarin Forms 应用程序发送推送通知...我没有收到通知
要发送通知,我只需从输出窗口中复制 token ,将我的应用程序置于后台,然后将 token 粘贴到 Firebase 通知生成器中。
我收到了 FCM token ,所以我的应用肯定在与 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
关于firebase - 为什么我的 Xamarin.iOS 应用程序没有收到来自 Google Firebase 的推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54522369/
相关文章:
python - API 网关 - 自定义授权方无法正常工作
c++ - 如何在 Visual Studio Code 中构建和运行作为发布版的 C++ 应用程序
listview - 只允许扩展一个 ExpansionTile
sql - 状态 : Failure -Test failed: IO Error: An exis
python - GAE : Why does GAE perform worse than nor
git - Jenkins 管道在远程源提取期间失败(无法更新本地引用)
graphql - Shopify graphql 客户创建