美文网首页
遇到iOS网址打不开的情况

遇到iOS网址打不开的情况

作者: 又又轻 | 来源:发表于2018-07-20 15:45 被阅读393次

    看到很多网上说设置清除缓存
    self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:htmlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0];

    貌似这个我也没用,我出现的bug是版本跟新后网址在iphone手机上打不开,新建过一个工程后是可以打开的,一开始认为是UIWebView的bug,最后一气之下卸载重新App Store上安装居然可以打开网址了。。。。。
    最后后台大佬告诉我说iOS是需要做一个登录的验证什么的,具体搞后端的肯定明白

    开始以为是未加入证书验证,然并不是。

    
    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge; {
        NSLog(@"WebController Got auth challange via NSURLConnection");
        
        if ([challenge previousFailureCount] == 0) {
            _authenticated = YES;
            NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
            [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
            
        } else {
            [[challenge sender] cancelAuthenticationChallenge:challenge];
            
        }
        
    }
    // We use this method is to accept an untrusted site which unfortunately we need to do, as our PVM servers are self signed.
    - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
        return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
    }
    #pragma mark - NSURLConnectionDataDelegate
    
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
        NSLog(@"WebController received response via NSURLConnection");
        // remake a webview call now that authentication has passed ok.
        _authenticated = YES;
        [self.webView loadRequest:_request];
        // Cancel the URL connection otherwise we double up (webview + url connection, same url = no good!)
        [_urlConnection cancel];
        
    }
    

    我真是什么bug都能碰见啊

    相关文章

      网友评论

          本文标题:遇到iOS网址打不开的情况

          本文链接:https://www.haomeiwen.com/subject/twcqmftx.html