iOS WebView 会奔溃的情景

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]]];

self.urlString 如果是 www.baidu.com,并非http://www.baidu.com

webView 是 WKWebView 直接奔溃,UIWebView 会有信息输出:NSURLConnection finished with error - code -1100

WKWebView的奔溃还不能用捕捉异常阻止啊。。。好坑啊~~~

    @try {
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]]];
    } @catch (NSException *exception) {
        
    } @finally {
        
    }
    

该问题的解决方案:

    if ([self.urlString isKindOfClass:[NSString class]]) {
        if ([self.urlString lqs_containsString:@"http://"] == NO ||
            [self.urlString lqs_containsString:@"https://"] == NO) {
            self.urlString = [NSString stringWithFormat:@"http://%@", self.urlString];
        }
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]]];
    }