2010-02-14 3 views
0

네트워크 프로그래밍 및 espacially objective-c 네트워킹에 처음 ...
내 컴퓨터에서 네트워크 인터페이스를 종료하거나 홍조 모드로 설정하더라도, NSURLConnection은 이 응용 프로그램이 종료된다는 놀랄만 한 결과를 반환하지 않습니다. 나는 모든 올바른 콜백 메소드에있는 NSURLConnection 프로토콜을 준수네트워크가 다운 된 경우에도 nsurlconnecion이 nil을 반환하지 않습니다.

...

가 어떻게 클라이언트가 인터넷에 연결이없는 경우를 처리 할? 내가 서버에 로그인 데이터를 게시

코드는 : 당신이 연결 개체를 해제하고 있기 때문에

-(void)Login { 
    ... 
    NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:post delegate:self]; 
    if (theConnection==nil) { 
     //Here I want to show an alert but this case never happens.... 
    } 
    else { 
     receivedData=[[NSMutableData data] retain]; 
    } 
} 
... 


//This callback is called correctly but no alert shows up and after this method app dies. 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
    [connection release]; 
    [receivedData release]; 
    [self setLoggedIn:NO]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
               message:[error localizedDescription] 
               delegate:self 
               cancelButtonTitle:@"OK" 
               otherButtonTitles: nil]; 
    [alert show]; 
    [alert release]; 
} 

답변

2

앱은 아마 당신이 그것을 소유하지 않더라도 충돌합니다. 대리자 메서드에서 [connection release];을 제거하십시오.

+0

... 그리고// "& /"# % & 님의 노벨상은 저에게로갑니다 ... 고맙습니다! – niel41

관련 문제