1

I'm trying to connect to a self-signed HTTPS server on iOS 9.1.

I'm using :

[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];

And I get an error saying that the certificate is not valid:

Error Domain=NSURLErrorDomain Code=-1202 "<French error saying the certificate is invalid" 
UserInfo=
   {NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x13c768140>, 
    NSLocalizedRecoverySuggestion=<French recovery suggestion asking if the user wants to connect anyway>, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9813, NSErrorPeerCertificateChainKey=<CFArray 0x13d82ffe0 [0x1a1242b68]>

I've tried adding all possible transport security exceptions, my current attempt is:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>mydomain.org</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>

I've also tried NSAllowsArbitraryLoads but even that doesn't work. I have several .plist files (cocoapods and tests), I think it's in the correct one (App/Supporting Files/Info.plist).

Any idea of what could be wrong?

Julien
  • 9,312
  • 10
  • 63
  • 86

3 Answers3

1

You need add this at the end like this

<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73
0

So this was an NSURLConnection problem, and not app transport.

For the records, and for those who may face the same problem, I've fixed it temporarily by calling a private method (do not do this):

+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;

This won't be accepted by Apple. The real solution is with delegate methods, I'll edit this answer when we will work on this (my client is a "developer", so I used his option, he said we'll figure out later, and we're in a hurry...)

Community
  • 1
  • 1
Julien
  • 9,312
  • 10
  • 63
  • 86
0

I have solved issues using following steps

  1. Open Project's plist file
  2. Add a key "NSAppTransportSecurity" and on Type Dictionary
  3. Add a inner key "NSAllowsArbitraryLoads" as Boolean YES

enter image description here

Piyush
  • 1,156
  • 12
  • 20