【发布时间】: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。