0

I tried to post device token and device details to a web service using almofire. But I am getting response like the following

UserInfo={NSUnderlyingError=0x7fba3a590e50 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://----/register, NSErrorFailingURLKey=http://---/register, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

In Objective c, I tried to set all the values as httpHeader, In swift i used the following code..

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)
                    }
            }

Please assist me..

2 Answers2

1

You should disable the App Transport Security.

You have to set the NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your .plist file. Hope this helps!

enter image description here

Mudith Chathuranga Silva
  • 7,253
  • 2
  • 50
  • 58
-1
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
</plist>

Add This key to your info.plist enter image description here

Tarun Seera
  • 4,212
  • 4
  • 27
  • 41