C#Xamarin iOS RegisteredForRemoteNotifications从未触发过

问题描述 投票:1回答:1

嗨!

我正在尝试使用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());
            });
        });
    }
c# ios azure xamarin notifications
1个回答
0
投票

您检查了配置文件吗?

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

enter image description here

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

我希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.