问题
I'm trying to setup Azure Push Notifications for iOS app using Swift. I followed the documentation provided here https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-ios-get-started-push.
Here is my ClientManager
class ClientManager {
static let sharedClient = MSClient(applicationURLString: "https://ar-todo.servicebus.windows.net:443")
}
As per the documentation I have replaced %AppUrl% with the URL of my Azure Mobile App backend. But I get the following error when my device tries to register for Push Notification.
Error registering for notifications: Optional("Error Domain=com.Microsoft.MicrosoftAzureMobile.ErrorDomain Code=-1302 \"
401
Missing authorization token.TrackingId:a027aaec-887d-49c3-acf7-00d1503fd94b_G4,TimeStamp:2/14/2016 10:19:48 PM\" UserInfo={com.Microsoft.MicrosoftAzureMobile.ErrorRequestKey= { URL: https://ar-todo.servicebus.windows.net:443/push/installations/F3C97DFA-2B7A-4DDE-902A-45A2C5C48305 }, com.Microsoft.MicrosoftAzureMobile.ErrorResponseKey= { URL: https://ar-todo.servicebus.windows.net:443/push/installations/F3C97DFA-2B7A-4DDE-902A-45A2C5C48305 } { status code: 401, headers {\n \"Content-Type\" = \"application/xml; charset=utf-8\";\n Date = \"Sun, 14 Feb 2016 22:19:47 GMT\";\n Server = \"Microsoft-HTTPAPI/2.0\";\n
\"Transfer-Encoding\" = Identity;\n} }, NSLocalizedDescription=401
Missing authorization token.TrackingId:a027aaec-887d-49c3-acf7-00d1503fd94b_G4,TimeStamp:2/14/2016 10:19:48 PM}")
I'm sure that my AppURL is missing some information. Can someone successful in configuring this shed some light?
回答1:
Make sure that the App Service URL matches the one in the Azure portal (if you could post a screenshot, that would be awesome).
One thing that stands out is that you are using a port number at the end of the URL. Remove it and try running the app again.
回答2:
You have the URL for your Notification Hub in your MSClient constructor, where it should have the URL for your Mobile App instead. From the page you linked:
Add file ClientManager.swift with the following contents. Replace %AppUrl% with the URL of the Azure Mobile App backend.
class ClientManager { static let sharedClient = MSClient(applicationURLString: "%AppUrl%") }
来源:https://stackoverflow.com/questions/35398851/ios-push-notification-on-azure-notification-hubs