Allow unverified ssl certificate in UIWebview

后端 未结 7 1922
北恋
北恋 2020-12-02 07:05

I\'m embedding a website in a UIWebView. During development I have it pointed at localhost. The problem is that whenever it hits a \"https://\" url it doesn\'t load. When I

相关标签:
7条回答
  • 2020-12-02 07:43

    If it's just for testing during development you can create a category on NSURLRequest and override the following private method:

    #if DEBUG
    
    @implementation NSURLRequest (NSURLRequestWithIgnoreSSL) 
    
    + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
    {
        return YES;
    }
    
    @end
    
    #endif
    

    Just put this anywhere in one of your .m files (e.g. app delegate), or put it in it's own .m file. You don't need a matching header file.

    The #if DEBUG is a precaution to prevent you from accidentally leaving it enabled when you submit to Apple, but if you need it to work in a release build then remove that (and make sure you remember to restore it or remove this category before you submit to Apple).

    0 讨论(0)
提交回复
热议问题