问题
I'm using Swift 2 and Alamofire with both iOS 9 and iOS 8. In iOS 8 all my requests to my API work fine. In iOS 9 they immediately fail with a -1004 NSURLErrorDomain with the message "Could not connect to the server.". I read about Apple's change with App Transport Security and already added the entry to my Plist to disable it and allow insecure connections.
I'm at a loss as to the reason for this error...any help would be great!
回答1:
After messing around with a ton of different keys and values to make it work, I finally have come up with this to make it function in iOS9.1:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>mydomain.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSRequiresCertificateTransparency</key>
<false/>
</dict>
</dict>
</dict>
After I added the last one NSRequiresCertificateTransparency
and set that to false it worked, so that's probably the most important one.
来源:https://stackoverflow.com/questions/32936183/swift-ios-9-nsurlerrordomain-error-1004