博客> UIWebView 处理 authentication 方法
UIWebView 处理 authentication 方法
2017-12-13 18:27 评论:0 阅读:300 vistatinchao
cocoapods

https://www.oschina.net/question/54100_38005

pragma mark NSURLConnectionDelegate代理

  • (void)connection:(NSURLConnection )connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge )challenge { [MBProgressHUD hideHUDForView:self.showWebView animated:YES];

    NSString *httpType = NSURLAuthenticationMethodHTTPBasic; //如果是http代理,其它代理方法类似 if ([challenge.protectionSpace.authenticationMethod isEqualToString:httpType]) {

    if ([challenge previousFailureCount] == 0) {
        /* SET YOUR credentials, i'm just hard coding them in, tweak as necessary */
        [[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"mpndb" password:@"mpndb" persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
    } else {
        [[challenge sender] cancelAuthenticationChallenge:challenge];
    }

    }

}

  • (void)connection:(NSURLConnection )connection didFailWithError:(NSError )error { [MBProgressHUD hideHUDForView:self.showWebView animated:YES];

}

pragma mark webView代理

  • (void)webViewDidStartLoad:(BZWebView *)webView { [MBProgressHUD showHUDAddedTo:self.showWebView animated:YES]; }

  • (void)webViewDidFinishLoad:(BZWebView *)webView { [MBProgressHUD hideHUDForView:self.showWebView animated:YES]; }

-(void)webView:(BZWebView )webView didFailLoadWithError:(NSError )error { [MBProgressHUD hideHUDForView:self.showWebView animated:YES]; }

  • (BOOL)webView:(UIWebView )webView shouldStartLoadWithRequest:(NSURLRequest )request navigationType:(UIWebViewNavigationType)navigationType { NSURLRequest *req = [NSURLRequest requestWithURL:request.URL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0]; self.connect = [[NSURLConnection alloc] initWithRequest:req delegate:self]; return YES; }
收藏
0
sina weixin mail 回到顶部