iOS Push Notification on Azure Notification Hubs

半世苍凉 提交于 2019-12-13 07:19:00

问题


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 \"401Missing 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=401Missing 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!