paranitips

Never stop learning! がモットーのゆるふわエンジニアブログ

NSURLRequestでSSL証明書を無視する

NSURLRequestを拡張することでSSLの証明書を無視します。

#import <Foundation/Foundation.h>
 
@interface NSURLRequest (IgnoreSSL)
 
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
 
@end
#import "NSURLRequest+IgnoreSSL.h"
 
@implementation NSURLRequest (IgnoreSSL)
 
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host
{
    // このドメインの証明書エラーを無視する
    if ([host hasSuffix:@"hoge.com"])
    {
        return YES;
    }
    else
    {
        return NO;
    }
}
 
@end

アプリ申請時はRejectリスクがあるので解除しておいたほうがいいかもしれません。