zoukankan      html  css  js  c++  java
  • 用UIWebView显示https的方法

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    {
        NSLog(@"Did start loading: %@ auth:%d", [[request URL] absoluteString], _authenticated);
        
        if (!_authenticated) {
            _authenticated = NO;        
            _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];        
            [_urlConnection start];        
            return NO;
        }    
        return YES;
    }
    
    #pragma mark - NSURLConnection Delegate
    
    - (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];
        }
    }
    
    
    - (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];    
    }
    
    // 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];
    }

    就是利用NSURLConnection连接去跳过webview本身的加载。

  • 相关阅读:
    汉语-词语-从容:百科
    汉语-词语-伶俜:百科
    汉语-词语-心迹:百科
    汉语-词语-痛楚:百科
    汉语-词语-痛苦:百科
    汉语-词语:散步
    汉语-词语-憎恨:百科
    2455 繁忙的都市
    P2820 局域网
    NOIP2013Day1T3 表示只能过一个点
  • 原文地址:https://www.cnblogs.com/mystory/p/3083490.html
Copyright © 2011-2022 走看看