2013-02-27 2 views
0

UIWebView 인증을 위해 NSURL 연결을 생성 중입니다. 괜찮 으면 좋겠지 만 어떤 이유로 권한을 부여받을 수는 없습니다. 잘못된 암호를 입력하면 올바른 암호로 다시 로그인 할 수 없습니다. NSURLconnection을 종료하는 가장 좋은 방법은 무엇입니까?NSURLConnection ios를 종료하십시오

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
    NSString *errorText = [[error userInfo] description]; 
    NSLog (@"----------------------------------------------"); 
    NSLog (@"STEP 4 - connection didFailWithError"); 
    NSLog (@"Error message: %@", errorText); 
    connection = nil; 
} 

하지만 어떤 이유로 작동하지 않습니다 :

나는이 시도.

+0

접속을 마킹하기 전에 API 호출을 취소하려고 했습니까? http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html – Saurabh

+0

포인터를 nil로 설정하면 아무런 효과가 없습니다. – Felix

답변

0

NSURLConnection을 원하는대로 종료하지 않아도됩니다.

자격 증명 (로그인/패스)를 변경하려면 다음있는 NSURLConnection 위임 방법을 구현 :

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

을 새 자격 증명을 제공 할 수있는 변화가이 방법. 다음과 같은 것 :

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
    NSLog(@"received authentication challenge"); 
    NSURLCredential *newCredential = [NSURLCredential credentialWithUser:@"USER" 
                   password:@"PASSWORD" 
                  persistence:NSURLCredentialPersistenceForSession]; 
    NSLog(@"credential created"); 
    [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; 
    NSLog(@"responded to authentication challenge");  
}