It really amazes me that a company like Microsoft doesn't give you readable error messages. I'm simply trying to register a device into a notification hub in our 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);
}
}
Register callback
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");
});
}
Here's the error message I get back
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}
So the only message I get back is unauthorized
, just wondering what some of the reasons why it would come back as unauthorized
when I'm using the endpoint url given in azure, and the notification hub name.
My issue was with some of the documentation I saw which tells you to do this
//// 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);
When really all that's necessary is this
var hub = new WindowsAzure.Messaging.SBNotificationHub(AzureServiceBusConnectionString, AzureHubName);
So when you're instantiating a new SBNotificationHub, you just supply the connection string and hub name. Without doing the CreateListenAccess