gpt4 book ai didi

ios - didReceiveAuthenticationChallenge 失败后 Webview 不工作

转载 作者:行者123 更新时间:2023-11-29 12:50:21 26 4
gpt4 key购买 nike

我按下按钮调用波纹管按钮 Action 函数

- (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) 会出现authenticaion登录 View
3) 输入错误的用户名和密码按'登录'比重新显示身份验证登录 View
4) 提供当前用户名和密码而不是调用
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

webview 加载开始。但不显示

最佳答案

我也遇到了同样的问题。我通过引用这个答案修复了我的 here

并添加一个 NSURLConnection 委托(delegate)

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

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

希望这能解决您的问题。

关于ios - didReceiveAuthenticationChallenge 失败后 Webview 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22558527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com