Giter Site home page Giter Site logo

Comments (4)

xiubojin avatar xiubojin commented on July 28, 2024

这个不是WebView的问题,建议让你们server好好检查一下代码和配置

from jxbwkwebview.

 avatar commented on July 28, 2024

🤔🤔🤔老哥你好,我把Safari加载相同网页的截图发给你看,就是为了说明这个网站用其他浏览器打开是正常的。。

from jxbwkwebview.

xiubojin avatar xiubojin commented on July 28, 2024

from jxbwkwebview.

 avatar commented on July 28, 2024

嗯嗯,可以了

`- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler {
NSString *hostName = webView.URL.host;

NSString *authenticationMethod = [[challenge protectionSpace] authenticationMethod];
if ([authenticationMethod isEqualToString:NSURLAuthenticationMethodDefault]
    || [authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic]
    || [authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPDigest]) {
    NSString *title = @"网页认证";
    NSString *message = [NSString stringWithFormat:@"%@ 需要用户名和密码", hostName];
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"用户名";
    }];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"密码";
        textField.secureTextEntry = YES;
    }];
    [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        NSString *userName = ((UITextField *)alertController.textFields[0]).text;
        NSString *password = ((UITextField *)alertController.textFields[1]).text;
        
        NSURLCredential *credential = [[NSURLCredential alloc] initWithUser:userName password:password persistence:NSURLCredentialPersistenceNone];
        
        completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
        
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
    }]];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertController animated:YES completion:^{}];
    });
}
else if ([authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
    // needs this handling on iOS 9
    completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
    // or, see also http://qiita.com/niwatako/items/9ae602cb173625b4530a#%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%82%B3%E3%83%BC%E3%83%89
}
else {
    completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
}

}`

from jxbwkwebview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.