gpt4 book ai didi

ios - tony million Reachability 在连接时表示无法访问

转载 作者:技术小花猫 更新时间:2023-10-29 11:07:38 26 4
gpt4 key购买 nike

我已经搜索过,但没有发现像我这样的问题。我确定这是我看过的东西。

我正在使用 tony million 的可达性 block 方法。当我有互联网然后没有互联网时,它工作得很好。警报出现并且工作正常。

但是,当我没有互联网然后我上网时会弹出相同的警报

我的代码是

-(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 *reach = [Reachability reachabilityWithHostname:@"www.jportdev.com"];
if ([reach isReachable]){
// Reachable
//NSLog(@"is reachable.......");
}else{
// not Reachable
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network is unavaliable!" message:@"Some content in this application might not be avaliable without network connectivity." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
alert = nil;
}

关于ios - tony million Reachability 在连接时表示无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19367351/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com