2013-03-27 56 views
0

我可以使用NSURL進行身份驗證,用戶可以分配用戶名和密碼。但是,我又遇到了另一個問題。如果我打開這個,http://html5test.com/,它也彈出並詢問用戶名和密碼。即使它不應該得到,我也得到認證。我想知道該怎麼做。NSURLConnection身份驗證挑戰,即使它不應該

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    if(!_auth) 
    { 
    connection_for_auto = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
      firsttimeonly=TRUE; 
     [connection_for_auto start]; 
     NSLog(@"Request >> %@ and !firsttimeonly",request); 
     return NO; 
    } 
    self.lbl_error.hidden = YES; //hide error message label 
    return YES; 

} 

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 

    checkTochangeUIalert=TRUE; 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Login" 
                message:nil 
                delegate:self 
              cancelButtonTitle:@"Cancel" 
              otherButtonTitles:@"OK",@"Auto", nil]; 

    alertView.transform=CGAffineTransformMakeScale(1.0, 0.75); 
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; 
    [alertView show]; 
} 

回答

0

我想我已經找到了一種方法。我需要檢查我使用什麼樣的身份驗證方法。

if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic] || [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM]) 
{ 
............. 
} 
相關問題