-- iOS (iPhone)
NSURLConnection sendSynchronousRequest 사용 시 유효하지 않은 인증서 처리
어린왕자악꿍
2015. 3. 2. 08:04
NSURLConnection sendSynchronousRequest로 https를 요청할 때, 사이트가 유효하지 않은 인증서를 사용할 경우 alert이 떠서 폰에서는 멈춘 것처럼 나타난다.이 경우 유효하지 않다는 경고창을 무시시켜야 하는데, 여기서는 동기방식인 경우에 대한 처리를 기술한다.
[NSURLRequest+NSURLRequestWithIgnoreSSL.h]
#import <Foundation/Foundation.h>
@interface NSURLRequest (NSURLRequestWithIgnoreSSL)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host;
@end
[NSURLRequest+NSURLRequestWithIgnoreSSL.m]
#import "NSURLRequest+NSURLRequestWithIgnoreSSL.h"
@implementation NSURLRequest (NSURLRequestWithIgnoreSSL)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
return YES;
}
위처럼 NSURLRequest 카테고리를 하나 생성하여 사용하는 소스에 해당 해더만 import해주면 된다.
필자의 경우는 <AppName>-Prefix.pch 에 전역적으로 선언해두었다.