我尝试使用 almofire 将设备 token 和设备详细信息发布到 Web 服务。但我收到如下回复
UserInfo={NSUnderlyingError=0x7fba3a590e50 {错误域=kCFErrorDomainCFNetwork Code=-1022“(null)”},NSErrorFailingURLStringKey=http://----/register , NSErrorFailingURLKey= http://---/register , NSLocalizedDescription=无法加载资源,因为应用程序传输安全策略要求使用安全连接。
在 Objective c 中,我尝试将所有值设置为 httpHeader,在 swift 中我使用了以下代码..
let params = ["notification_token":deviceToken,"device_identifier":deviceIdentifier,"advertising_identifier":"","model":deviceModel,"os":deviceOS,"os_version":deviceOSVersion,"app_version":deviceAppVersion]
let jsonData = try! NSJSONSerialization.dataWithJSONObject(params, options: [])
request(.POST, urlString, parameters: params,encoding:.JSON).responseJSON
{
response in
if let JSON = response.result.value
{
// print("A JSON Result :\(JSON)")
delegate.API_CALLBACK_RegisterApp!(JSON as! NSDictionary)
}
else
{
delegate.API_CALLBACK_Error(0,errorMessage: response.result.error!.description)
}
}
请帮助我..
最佳答案
您应该禁用应用程序传输安全性。
您必须在 .plist 文件中的 NSAppTransportSecurity 字典下将 NSAllowsArbitraryLoads 键设置为 YES。希望这有帮助!
关于ios - 尝试访问 API 时收到错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36125410/