【发布时间】:2011-11-15 09:10:47
【问题描述】:
我有一个应用程序需要在首次启动时从服务器加载其数据,我想添加一条消息提醒用户以防互联网连接不活动,因为它现在完成了它在没有连接时崩溃.谢谢。
【问题讨论】:
我有一个应用程序需要在首次启动时从服务器加载其数据,我想添加一条消息提醒用户以防互联网连接不活动,因为它现在完成了它在没有连接时崩溃.谢谢。
【问题讨论】:
如果它与失败的互联网连接有关,您可以使用 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]);
}
【讨论】: