Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用程序需要等待Internet连接_Ios_Objective C - Fatal编程技术网

Ios 应用程序需要等待Internet连接

Ios 应用程序需要等待Internet连接,ios,objective-c,Ios,Objective C,场景非常简单,我的应用程序在激活时会查找信息。大多数情况下,它只是简单地使用缓存,但是,在某些情况下,它需要一个Internet连接来请求所需的信息 我使用了Reachability()来确定是否存在可用的活动连接。问题在于,iPhone在一段时间内处于非活动状态后,需要几秒钟才能激活连接。这意味着应用程序会发现没有可用的连接,并显示错误消息 我希望应用程序首先检查是否存在可用连接: Reachability *reachability = [Reachability reachabilityW

场景非常简单,我的应用程序在激活时会查找信息。大多数情况下,它只是简单地使用缓存,但是,在某些情况下,它需要一个Internet连接来请求所需的信息

我使用了Reachability()来确定是否存在可用的活动连接。问题在于,iPhone在一段时间内处于非活动状态后,需要几秒钟才能激活连接。这意味着应用程序会发现没有可用的连接,并显示错误消息

我希望应用程序首先检查是否存在可用连接:

Reachability *reachability = [Reachability reachabilityWithHostname:URL_LOTTOTALL_WEB];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
if (internetStatus == NotReachable) {
} else {
}

如果没有可用的连接,我想在几秒钟后重试(可能2或3)。如果仍然没有可用的连接,则显示错误消息。对实现这一点的简单实现有什么建议吗?

尝试使用
可达性的回调块,如中所述


尝试使用
可达性的回调块,如中所述


你也可以尝试使用while循环你也可以尝试使用while循环
internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
// Internet is reachable
internetReachableFoo.reachableBlock = ^(Reachability*reach)
{
    // Update the UI on the main thread
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"Yayyy, we have the interwebs!");
    });
};

// Internet is not reachable
internetReachableFoo.unreachableBlock = ^(Reachability*reach)
{
    // Update the UI on the main thread
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"Someone broke the internet :(");
    });
};

[internetReachableFoo startNotifier];