我有一个应用程序需要在首次启动时从服务器加载其数据,我想添加一条消息,以便在互联网连接未激活时提醒用户,因为它现在已经完成,当没有连接时它会崩溃。谢谢。
答案 0 :(得分:4)
如果它与失败的互联网连接有关,您可以使用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]);
}
答案 1 :(得分:1)
使用Reachability类检查网络连接 http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html