Xamarin 通知中心注册错误

Xamarin Notification Hub Register error

像 Microsoft 这样的公司没有给您可读的错误消息,这真的让我感到惊讶。我只是想在我们的 azure 中将设备注册到通知中心。

if (App.DeviceInfo.DeviceManufacturer == "Apple")
{
    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);
    }
}

注册回调

public override void RegisteredForRemoteNotifications(UIApplication app, NSData deviceToken)
{
    //// Connection string from your azure dashboard
    var cs = WindowsAzure.Messaging.SBConnectionString.CreateListenAccess(
        new NSUrl(AzureServiceBusConnectionString),
        AzureHubName);

    // Register our info with Azure
    var hub = new WindowsAzure.Messaging.SBNotificationHub(cs, AzureHubName);
    hub.RegisterNativeAsync(deviceToken, null, err =>
    {
        if (err != null)
        {
            Console.WriteLine("Error: " + err.Description);
            Console.WriteLine(err.DebugDescription);
        }
        else
            Console.WriteLine("Success");
    });
}

这是我返回的错误信息

Error: Error Domain=WindowsAzureMessaging Code=401 "URLRequest failed for { URL: https://****.servicebus.windows.net/****/Registrations/?$filter=deviceToken+eq+'****'&api-version=2013-04 } with status code: unauthorized" UserInfo={NSLocalizedDescription=URLRequest failed for { URL: https://****.servicebus.windows.net/newsernotificationhub/Registrations/?$filter=deviceToken+eq+'****'&api-version=2013-04 } with status code: unauthorized}

所以我收到的唯一消息是 unauthorized,只是想知道当我使用给定的端点 url 时它会返回 unauthorized 的一些原因天蓝色,以及通知中心名称。

我的问题是我看到的一些文档告诉你这样做

//// Connection string from your azure dashboard
var cs = WindowsAzure.Messaging.SBConnectionString.CreateListenAccess(
   new NSUrl(AzureServiceBusConnectionString),
   AzureHubName);

// Register our info with Azure
var hub = new WindowsAzure.Messaging.SBNotificationHub(cs, AzureHubName);

当真的只需要这个

var hub = new WindowsAzure.Messaging.SBNotificationHub(AzureServiceBusConnectionString, AzureHubName);

因此,当您实例化一个新的 SBNotificationHub 时,您只需提供连接字符串和集线器名称。没有做 CreateListenAccess