我已经搜索过了,但没有找到和我的问题类似的情况。 我相信这是我忽视了某些东西。
我正在使用Tony Million的可达性块方法。 当我有互联网连接时,它工作得很好,没有互联网连接时,警报会弹出并正常工作。
但是,当我没有互联网连接,然后重新连接上互联网时,同样的警报弹出。
我的代码如下:
-(void)reachabilityBlock
{
// allocate a reachability object
Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"];
// tell the reachability that we DONT want to be reachable on 3G/EDGE/CDMA
reach.reachableOnWWAN = YES;
reach.reachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
//NSLog(@"REACHABLE! block");
[self newsTableViewRefresher];
});
};
reach.unreachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
//NSLog(@"UNREACHABLE! block");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"No Network found!"
message: @"You have no wifi or cellular connection available. Please connect to a WIFI or cellular network."
delegate: self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
});
};
[reach startNotifier];
[self.refreshControl endRefreshing];
}
我的问题是为什么在我连接到互联网时会弹出"无法访问"的警告提示?谢谢您的时间。
[Reachability reachabilityForInternetConnection];
比使用[Reachability reachabilityWithHostname:@"www.google.com"];
获得更好的结果。 - Alec