我正在使用 Xamarin Forms,目前正在尝试获取推送通知以与 iOS 项目配合使用。我已关注this https://developer.xamarin.com/guides/ios/platform_features/user-notifications/deprecated/remote_notifications_in_ios/Xamarin 指南向我的 iOS 应用程序添加通知,但从未调用 RegisteredForRemoteNotifications 方法。
我还创建了推送通知证书并启用了后台通知。甚至 FailedToRegisterForRemoteNotifications 也永远不会被调用。
我能做些什么?
PS:我使用的是装有 iOS 10 的 iPhone 5s,所以我也阅读了this https://blog.xamarin.com/getting-started-with-the-ios-10-notification-framework/在用户通知框架上发布。
注意 Xamarin 指南顶部的大注释的要点,很多人有时会忽略它们。
注意:本节中的信息适用于 iOS 9 及更早版本
留在这里是为了支持旧版 iOS 版本。对于 iOS 10 和
稍后,请参阅用户通知框架指南以获取支持
iOS 设备上的本地通知和远程通知。
如果能看到一些您自己的代码示例就好了,但这既不存在也不存在。
正如您所说,您计划使用 iOS 10 设备,这是我们使用的从 10.3 向后运行的代码。此代码位于 AppDelegate 类内的 FinishedLaunching() 方法中。
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// iOS 10 or later
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
{
if (granted)
{
InvokeOnMainThread(() => {
UIApplication.SharedApplication.RegisterForRemoteNotifications();
});
}
});
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = ADSelf;
}
else
{
// iOS 9 or before
var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}
关键实际上是以下几行:
UIApplication.SharedApplication.RegisterForRemoteNotifications();
OR
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)