Mat*_*zzo 7 c# push-notification xamarin.ios xamarin.forms
我正在使用 Xamarin Forms,目前正在尝试获取推送通知以处理 iOS 项目。我已按照此Xamarin 指南向我的 iOS 应用程序添加通知,但从未调用过 RegisteredForRemoteNotifications 方法。
我还创建了推送通知证书和启用的后台通知。甚至 FailedToRegisterForRemoteNotifications 也从未被调用。
我能做什么?
PS:我使用的是装有 iOS 10 的 iPhone 5s,所以我还在用户通知框架上阅读了这篇文章。
注意 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);
}
Run Code Online (Sandbox Code Playgroud)
关键实际上是以下几行:
UIApplication.SharedApplication.RegisterForRemoteNotifications();
Run Code Online (Sandbox Code Playgroud)
或者
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5558 次 |
| 最近记录: |