我实际上坚持使用Apple的Reachability类问题 .
我正在检查互联网连接:
Reachability *r = [Reachability reachabilityWithHostName:@"http://google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if (internetStatus == NotReachable){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Keine Internetverbindung" message:@"Diese Applikation erfordert eine Internetverbindung. Bitte aktivieren Sie diese um die Inhalte korrekt darstellen zu können." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
else {
// The stuff if want to do with connection
}
我在模拟器和我的iPhone 4上测试过 . 它运行正常,但仅适用于WIFI . 如果我不在WIFI网络中,我仍会收到警告消息 . 谁能告诉我为什么它不检查iPhone的3G或移动数据网络连接?
1 回答
我解决了这个问题!也许我的问题是检查主机,而不是连接?
还是不知道! = d
iWasRobbed在本主题中给出的答案:
How to check for an active Internet connection on iOS or OSX?
帮助了我很多!