Internet连接不可用消息为iPhone应用程序

我有一个应用程序需要从服务器加载它的数据,当它第一次启动时,我想添加一个消息,提醒用户万一互联网连接不活动,因为它现在完成它现在崩溃,当没有连接。 谢谢。

如果它与失败的互联网连接相关,则可以使用NSURLConnectionDataDelegate方法之一:

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { UIAlertView*aview=[[UIAlertView alloc]initWithTitle:@"Connection Failed" message:@"Please check your internet connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ]; [aview show]; [aview release]; // Notify the user about the failure. NSLog(@"Reason:%@",[error description]); }