これを回避する方法です。
開発時などに役に立つTIPSだと思います。
エラーの例
2017-02-07 10:49:25.250 App[46178:1264401] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) 2017-02-07 10:49:25.253 App[46178:1264332] FADHttp failed -1200: https://mydomain/ An SSL error has occurred and a secure connection to the server cannot be made.
Info.plistにAppTransportSecurityを設定して、NSURLRequestをオーバーライドするコードを追加します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>NSAppTransportSecurity</key> | |
<dict> | |
<key>NSExceptionDomains</key> | |
<dict> | |
<key>mydomain.com</key> | |
<dict> | |
<key>NSIncludesSubdomains</key> | |
<true/> | |
<key>NSExceptionRequiresForwardSecrecy</key> | |
<false/> | |
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> | |
<true/> | |
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> | |
<false/> | |
</dict> | |
</dict> | |
</dict> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#ifdef DEBUG | |
@interface NSURLRequest (SSL) | |
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host; | |
@end | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSURLRequestOverrideNotSecureSSL.h" | |
#ifdef DEBUG | |
@implementation NSURLRequest(SSL) | |
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host { | |
return YES; | |
} | |
@end | |
#endif |
参考資料
[iOS 9] iOS 9 で追加された App Transport Security の概要 | Developers.IO http://dev.classmethod.jp/smartphone/iphone/ios-9-intro-ats/
Working with Apple’s App Transport Security
http://www.neglectedpotential.com/2015/06/working-with-apples-application-transport-security/
Aplle / Cocoa Keys / Information Property List Key Reference
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40016240