简体   繁体   English

未调用Xamarin.iOS RegisteredForRemoteNotifications

[英]Xamarin.iOS RegisteredForRemoteNotifications not called

I am using Xamarin Forms and am currently trying to get push notifications to work with the iOS project. 我正在使用Xamarin Forms,目前我正在尝试使用推送通知来处理iOS项目。 I have followed this Xamarin guide to add notifications to my iOS app but the RegisteredForRemoteNotifications method is never called. 我已按照 Xamarin指南向我的iOS应用添加通知,但从未调用RegisteredForRemoteNotifications方法。

I have also created both push notification certificates and enabled background notifications. 我还创建了推送通知证书和启用后台通知。 Even FailedToRegisterForRemoteNotifications is never called. 永远不会调用FailedToRegisterForRemoteNotifications。

What can I do? 我能做什么?

PS: I'm using an iPhone 5s with iOS 10 so I also read this post on the User Notifications Framework. PS:我正在使用带有iOS 10的iPhone 5s,所以我也在用户通知框架上阅读了这篇文章。

证书 供应Progile

Points for noticing the big note at the top of the Xamarin guide, a lot of people sometimes gloss over them. 注意Xamarin指南顶部的大音符,很多人有时会掩饰它们。

NOTE: The information in this section pertains to iOS 9 and prior, it has been left here to support older iOS versions. 注意:本节中的信息适用于iOS 9及更早版本,此处已保留用于支持较旧的iOS版本。 For iOS 10 and later, please see the User Notification Framework guide for supporting both Local and Remote Notification on an iOS device. 对于iOS 10及更高版本,请参阅用户通知框架指南,以支持iOS设备上的本地和远程通知。

It would have been nice to see some of your own code sample, but that's neither here nor there. 看到你自己的一些代码样本会很高兴,但这既不是在这里也不是在那里。

So as you said you plan on using iOS 10 devices, here is the code we use that works from 10.3 backwards.This code is in our FinishedLaunching() method inside the AppDelegate class. 所以当你说你计划使用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);
            }

The key really is the following lines: 关键是以下几行:

UIApplication.SharedApplication.RegisterForRemoteNotifications();

OR 要么

UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

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

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

I was having the same issue. 我遇到了同样的问题。 The fault was, the mobile phone didn't have an active internet connection! 问题是,手机没有活跃的互联网连接!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM