2012-02-13 150 views
1

我試圖通過網絡服務器驗證用戶身份,並在我的登錄視圖按鈕中調用以下方法觸摸來完成此操作。ios didReceiveAuthenticationChallenge狀態

- (void)connection:(NSURLConnection *)connection 
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    NSLog(@"challenge failure %d", [challenge previousFailureCount]); 

    // Access has failed two times... 
    if ([challenge previousFailureCount] == 0) 
    { 
     //NSLog(@"desc %@",[connection description]); 
     NSURLCredential *cred = [[[NSURLCredential alloc] initWithUser:userName.text password:passWord.text 
                  persistence:NSURLCredentialPersistenceForSession] autorelease]; 
     [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge]; 

     // need to call new view on correct authentication 

      [connection release]; 

    } 

    else {// Answer the challenge 

      UIAlertView *alert = [[UIAlertView alloc] 


           initWithTitle:@"Authentication error" 
           message:@"Invalid Credentials" delegate:self 
           cancelButtonTitle:@"Retry" 
           otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 



    } 

} 

是否有成功驗證後返回,這樣我可以使用該狀態並傳遞到下一個視圖顯示其他錯誤任何狀態。

+1

你不應該手動調用該方法,這是主機需要驗證時的回調。通常你會設置一個URL,例如'http:// user:[email protected]/...'並放手。 – 2012-02-13 11:53:42

+0

YOu是正確的..我實際上意味着調用NSURLConnection *連接= [[NSURLConnection分配] initWithRequest:請求委託:自我];當按下按鈕時,我在ibAction方法中調用它 – TechnocraT 2012-02-13 12:17:21

+1

實際上'connectionDidFinishLoading:'方法告訴你可以繼續下一步。 – 2012-02-13 13:40:49

回答

0

好吧,在我的評論說:

其實connectionDidFinishLoading:方法告訴你,你可以繼續到下一個步驟。

1

Jsut調用connectionDidFinishLoading:方法。