【发布时间】:2012-07-22 14:40:32
【问题描述】:
在我的应用程序中,我想在用户没有互联网连接时显示一条警报消息,我使用了下面的代码,但它从未进入此块它永远不会触发它从未调用过
我如何控制用户是否有互联网连接?
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"connect");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:@"check your internet connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
注意:我使用的是 iOS 5.1 版本,并且我已将我的代理放入 .h 文件中
【问题讨论】:
-
确保这个方法在你的 NSURLConnection 的委托中
-
我有代表:NSURLConnectionDataDelegate,NSURLConnectionDelegate
-
developer.apple.com/library/mac/#documentation/Foundation/… 在 NSURLConnectionDelegate 中。
标签: iphone ios ios5 nsurlconnection