C#Xamarin iOS RegisteredForRemoteNotifications从未触发过

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#Xamarin iOS RegisteredForRemoteNotifications从未触发过相关的知识,希望对你有一定的参考价值。

嗨!

我正在尝试使用Azure Notification Hub在我的xamarin ios应用上添加通知。

按照本教程(https://docs.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-started)后,我在appdelegate.cs文件中遇到问题:从不触发RegisteredForRemoteNotifications方法,因此我的应用程序无法在我的集线器上注册。

通知的所有权限都已完成,设置也是如此,我做了很多研究,没有一个解决方案适用于我的情况。我已经尝试过Xamarin.iOS RegisteredForRemoteNotifications not called

在我的FinishedLaunching方法中,我有:

if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
        UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (granted, error) => 
        {
            if (granted)
            {
                    InvokeOnMainThread(UIApplication.SharedApplication.RegisterForRemoteNotifications);
            }
        });
}
else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
        var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet());
        UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
        UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
        UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
        UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}

我的RegisteredForRemoteNotifications方法是:

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
    {
            Hub = new SBNotificationHub(Constants.ListenConnectionString, Constants.NotificationHubPath);

            Hub.UnregisterAllAsync(deviceToken, (error) => {
                if (error != null)
                {
                        Console.WriteLine("Error calling Unregister: {0}", error.ToString());
                        return;
                }

            NSSet tags = null; // create tags if you want
            Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => {
                    if (errorCallback != null)
                        Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
            });
        });
    }
答案

您检查了配置文件吗?

转到https://developer.apple.com/>帐户>证书>供应配置文件

enter image description here

一个是生产需要,一个是开发。创建它并在Mac上下载。

我希望有所帮助。

以上是关于C#Xamarin iOS RegisteredForRemoteNotifications从未触发过的主要内容,如果未能解决你的问题,请参考以下文章

C#Xamarin iOS RegisteredForRemoteNotifications从未触发过

C# Xamarin IOS:相当于 C# IOS Xamarin 中的 SystemClock.ElapsedRealtime()

C# Monotouch/Xamarin.iOS - 不支持推送导航控制器

C# Monotouch/Xamarin.iOS - 可滚动的 UIView

如何使用 xamarin.UITest 从 iOS 上的表格单元格中清除文本?

Xamarin UI 测试。获取控件的背景颜色 ios