未调用 Xamarin.iOS RegisteredForRemoteNotifications

Mat*_*zzo 7 c# push-notification xamarin.ios xamarin.forms

我正在使用 Xamarin Forms,目前正在尝试获取推送通知以处理 iOS 项目。我已按照Xamarin 指南向我的 iOS 应用程序添加通知,但从未调用过 RegisteredForRemoteNotifications 方法。

我还创建了推送通知证书和启用的后台通知。甚至 FailedToRegisterForRemoteNotifications 也从未被调用。

我能做什么?

PS:我使用的是装有 iOS 10 的 iPhone 5s,所以我还在用户通知框架上阅读了这篇文章。

证书 供应配置文件

Dig*_*1nt 5

注意 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)

  • 我知道,但 RegisteredForRemoteNotifications 从未被调用。那就是问题所在。 (6认同)

小智 5

如果是模拟设备,则无法注册该设备。


Mat*_*zzo 3

因此,在 AppStore 中发布后,它就开始工作了......