【问题标题】:Webview not working after didReceiveAuthenticationChallenge fail在 didReceiveAuthenticationChallenge 失败后 Webview 不工作
【发布时间】:2014-03-21 12:17:23
【问题描述】:

我按下按钮调用波纹管按钮动作功能

- (IBAction)buttonAction:(UIButton *)sender {
    NSURL *URL = [NSURL URLWithString:@"<url>”];
    NSURLRequest *request = [NSURLRequest requestWithURL:URL
                                             cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                         timeoutInterval:30.0];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [connection start];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge previousFailureCount] == 0) {
        _alert = [[EYAlertView alloc] init];
        [_alert initWithTitle:@"Authentication Required" message:@“<url>” block:^(Authentication *login) {
            if(login!=nil){
                NSURLCredential *newCredential = [NSURLCredential credentialWithUser:login.username
                                                                            password:login.password
                                                                         persistence:NSURLCredentialPersistenceSynchronizable];
                [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];

            }
        }];
    }
    else {
        NSLog(@“Login failed”);
        NSURL *URL = [NSURL URLWithString:@“<url>”];
        NSURLRequest *request = [NSURLRequest requestWithURL:URL
                                                 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                             timeoutInterval:30.0];

        NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [connection start];

    }
}

-(BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection{
    return YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSString *fullURL = @“<url>”;
    NSURL *url = [NSURL URLWithString:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webview loadRequest:requestObj];
}

1) 按下按钮调用 buttonAction:
2)会出现authentaion登录视图
3) 输入错误的用户名和密码按“登录”而不是重新显示身份验证登录视图
4) 提供当前用户名和密码而不是调用
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

webview 加载开始。但不显示

【问题讨论】:

  • 你有回复,但你确定你有数据吗?
  • @DipenChudasama 在调用 didReceiveResponse 后无法在 web 视图中工作。应用程序关闭并重新打开,而不是显示没有身份验证登录视图的 webview。

标签: ios uiwebview


【解决方案1】:

我也有同样的问题。我通过参考这个答案修复了我的here

并添加一个 NSURLConnection 的委托

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace{
NSLog(@"protectionSpace send yes");
return YES;
}

- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection;{
//Modified this to YES.
return YES;
}

希望这能解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 2014-12-23
    • 2016-02-21
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多