0
很新的網絡編程和特別客觀的c網絡...
即使我關閉了計算機上的網絡接口,或者將我的iPhone設置爲風險模式, NSURLConnection不會 返回零與應用程序死亡的不愉快的驚喜。即使網絡出現故障,nsurlconnecion也不返回nil
我符合NSURLConnection的協議與正確的回調方法...
所以,你會怎麼處理這種情況的客戶端沒有互聯網連接的情況下?
的代碼片段,我登錄數據上傳到服務器:
-(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];
}
...和諾貝爾獎&&#&#「#%&去找我... Thanx! – niel41 2010-02-14 19:30:30