我正在尝试使用Google Firebase向我的iOS Xamarin Forms App发送推送通知...我没有收到通知
要发送通知,我只是将令牌从输出窗口中复制出来,将我的应用置于后台,并将代币粘贴到Firebase notif构建器中。
我收到了FCM令牌,因此我的应用程序肯定正在与Firebase通讯。
到目前为止,我已经尝试过:
撤销我的Apple开发人员证书和配置文件,然后创建新证书。
我创建了一个新的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
答案 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