NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) in iOS 9 with Xcode 7.1

61,037

Solution 1

If you try to make HTTP requests with ATS enabled (using NSURLSession or libraries like AFNetworking), you’ll see errors like this.

Here’s how to disable ATS entirely. Open Info.plist, and add the following lines:

<key>NSAppTransportSecurity</key>
<dict>
 <key>NSAllowsArbitraryLoads</key>
 <true/>
</dict>

Your info.plist file should look like this

enter image description here

See this post: https://stackoverflow.com/a/31077483/6763322

Solution 2

From iOS 9 Onwards Apple Enforce To make HTTP Request with Specific Host for Security Purpose. //Also works on iOS 10 with Swift 3

For that, you need to Add NSAppTransportSecurity Dictionary into your .plist the file of Project. Then your plist will look something like this as follows.

Tap to see .Plist File Image

Here NSAllowArbitraryLoads basically means Connect to anything (this is probably BAD). Instead of this you can add a particular Host to be Connect.

enter image description here

Solution 3

I just ran it in the device instead of simulator.It started working

Share:
61,037
SAYAN NANDY
Author by

SAYAN NANDY

Updated on August 01, 2020

Comments

  • SAYAN NANDY
    SAYAN NANDY almost 4 years

    I am using iOS 9 as target & using Xcode 7.1, tried everything as my level best for all the solutions of ATS but didn't work. Below is the following error description coming at console. If any suggestion comes I will be obliged.

    Some of the key things here are -

    NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
    
    Error excluding Main.db from backup Error Domain=NSCocoaErrorDomain Code=4 "The file “Main.db” doesn’t exist." UserInfo={NSURL=file:///Users/Raj/Library/Developer/CoreSimulator/Devices/BC3A0589-3B9A-4AFD-8F2A-B1C92FA341DD/data/Containers/Data/Application/70B3043A-8553-41E5-A147-8508D08BF3E6/Documents/Main.db, NSFilePath=/Users/Raj/Library/Developer/CoreSimulator/Devices/BC3A0589-3B9A-4AFD-8F2A-B1C92FA341DD/data/Containers/Data/Application/70B3043A-8553-41E5-A147-8508D08BF3E6/Documents/Main.db, NSUnderlyingError=0x798465c0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
    2016-08-30 21:09:10.867 GFIM[80653:484899] SFOAuthCredentials:revokeRefreshToken: refresh token revoked. Cleared identityUrl, instanceUrl, issuedAt fields
    2016-08-30 21:09:10.871 GFIM[80653:484899] INFO|0|SFPasscodeManager|Resetting passcode upon logout.
    
    SFOAuthCredentials:revokeRefreshToken: refresh token revoked. Cleared identityUrl, instanceUrl, issuedAt fields
    

    These are the things might be the cause of issue.

    2016-08-30 21:09:19.095 GFIM[80653:484899] SFOAuthCoordinator:webViewDidStartLoad: host=test.salesforce.com : path=/
    2016-08-30 21:09:19.863 GFIM[80653:484962] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
    2016-08-30 21:09:19.983 GFIM[80653:484962] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
    2016-08-30 21:09:20.016 GFIM[80653:484962] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
    2016-08-30 21:09:20.054 GFIM[80653:484962] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
    2016-08-30 21:09:20.194 GFIM[80653:484962] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
    2016-08-30 21:09:20.956 GFIM[80653:484962] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
    2016-08-30 21:09:38.285 GFIM[80653:484899] SFOAuthCoordinator:webView:shouldStartLoadWithRequest: (navType=1): host=test.salesforce.com : path=/
    2016-08-30 21:09:38.311 GFIM[80653:484899] SFOAuthCoordinator:webViewDidStartLoad: host=test.salesforce.com : path=/
    2016-08-30 21:09:38.834 GFIM[80653:484899] SFOAuthCoordinator:webView:shouldStartLoadWithRequest: (navType=1): host=5-prod--stg.cs30.my.salesforce.com : path=/secur/frontdoor.jsp
    
  • SAYAN NANDY
    SAYAN NANDY over 7 years
    I did it but not working... Should I use http instead of https.
  • SAYAN NANDY
    SAYAN NANDY over 7 years
    If i use http then its showing "Remote Access Application Authorization".
  • auspicious99
    auspicious99 over 7 years
    This is missing a 5th line: </dict>
  • Abhijit Chakra
    Abhijit Chakra over 7 years
    I changed in my case its showing "App Transport Security Setting" inside that i have changed "Allow Arbitary load" Yes still it's not working.Any idea why?
  • Luke Bartolomeo
    Luke Bartolomeo over 7 years
    This will flag your app during review and you will have to justify your reasoning. Use AllowsArbitraryLoads for testing only. You need to explicitly list domains in production apps.