詢問用戶名和密碼的警報不是默認值。您必須自己提醒,或者您可以在代理功能調用時專門在代碼中提供用戶名和密碼。
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURLConnection *myConn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[myConn start];
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
{
[[NSURLCredentialStorage sharedCredentialStorage] setCredential:[NSURLCredential credentialWithUser:@"userName" password:@"passWord" persistence:NSURLCredentialPersistencePermanent] forProtectionSpace:[challenge protectionSpace]];
[myWebView loadRequest:[connection originalRequest]];
}