Ошибка регистрации концентратора уведомлений Xamarin
Меня действительно удивляет, что такая компания, как Microsoft, не предоставляет читаемых сообщений об ошибках. Я просто пытаюсь зарегистрировать устройство в центре уведомлений в нашей лазури.
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");
});
}
Вот сообщение об ошибке я получаю обратно
Ошибка: Ошибка домена =WindowsAzureMessaging Code=401 "Не удалось выполнить URLRequest для { URL: https://****.servicebus.windows.net/****/Registrations/?$ Filter=deviceToken+eq+'****'&api-version=2013-04 } с кодом состояния: не авторизован " UserInfo={NSLocalizedDescription=URLRequest не удалось для { URL: https://****.servicebus.windows.net/newsernotificationhub/Registrations/?$filter=deviceToken+eq+'****'&api-version=2013-04 } с кодом статуса: не авторизован}
Так что единственное сообщение, которое я получаю, это unauthorized
, просто интересно, каковы некоторые из причин, почему это вернется как unauthorized
когда я использую URL-адрес конечной точки, указанный в Azure, и имя концентратора уведомлений.
1 ответ
Моя проблема была с некоторой документацией, которую я видел, которая говорит вам сделать это
//// 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