Swift 2 - Xcode 7.0 Cannot Access HTTPS site with unstrusted SSL Certificate

前端 未结 5 857
死守一世寂寞
死守一世寂寞 2021-02-06 01:00

Experts, I\'m a Beginner in IOS 9 / XCODE 7 / Swift 2 Development Kit

I\'m trying to create an ios app that simply route to Web Application in HTTPS protocol. Below is

5条回答
  •  广开言路
    2021-02-06 01:32

    1- Create category "NSURLRequestCategory" -> after import this category to your bridge file created by xcode (don't forget to let xCode create one if you dont haven't) and put this code :

        @implementation NSURLRequest (NSURLRequestCategory)
    
    + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
    {
        return YES;
    }
    @end
    

    Create your load request UIWebView normally :

    webView.delegate = self
    let myURL = URL(string: Constants.URL_DOMAINE)
    let request = URLRequest(url: myURL!)
    webView.loadRequest(request)
    

    Enjoyyy :D

提交回复
热议问题