我UIWebView
要去一个有登录按钮的网站。按下登录按钮后(例如在 Safari 中),它会提示登录,然后调用通过 AD 进行身份验证的 Web 服务并将用户登录。我试图让它在我UIWebView
的 .didReceiveAuthenticationChallenge
叫。有任何想法吗?
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSLog(@"Authed = %d", _authed);
NSLog(@"Did start loading: %@ auth:%d", [[request URL] absoluteString], _authed);
NSString *theURL = [[request URL] absoluteString];
currentURL = [[request URL] absoluteString];
if (!_authed) {
_authed = NO;
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"shouldStartLoadWithRequest Return NO");
return NO;
}
NSLog(@"shouldStartLoadWithRequest Return YES");
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
{
NSLog(@"got auth challange");
NSLog(@"previousFailureCount = %d", [challenge previousFailureCount]);
ch = challenge;
[[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"myusername" password:@"mypassword" persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
{
NSLog(@"received response via nsurlconnection");
_authed = YES;
NSString *urladdress = currentURL;
NSURL *url = [NSURL URLWithString:urladdress];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[itemWebView loadRequest:urlRequest];
}
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection;
{
return NO;
}
有没有办法手动调用该didReceiveAuthenticationChallenge
方法?