iPhone应用程序的Internet连接不可用消息
我有一个应用程序,当它第一次启动时需要从服务器加载数据,我想添加一条消息,提醒用户如果internet连接没有激活,就像现在这样,当没有连接时它会崩溃。谢谢。使用可达性类检查网络连接iPhone应用程序的Internet连接不可用消息,iphone,ios,Iphone,Ios,我有一个应用程序,当它第一次启动时需要从服务器加载数据,我想添加一条消息,提醒用户如果internet连接没有激活,就像现在这样,当没有连接时它会崩溃。谢谢。使用可达性类检查网络连接 如果与internet连接失败有关,您可以使用NSURLConnectionDataDelegate方法之一: -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { UIAlertView*aview
如果与internet连接失败有关,您可以使用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]);
}