我想在应用程序启动时进行测试,如果设备已连接到互联网,如果未显示警告,通知用户必须将设备连接到互联网,请阻止他在未连接的情况下启动应用程序,并且在他随时断开连接以重新加载应用程序时,有点像《部落冲突》的原理……在互联网负载测试中,如果没有互联网,则该应用程序无法加载..断开连接,应用将重新启动。任何想法如何做到这一点?

最佳答案

使用reachability库。将其包括在AppDelegate中:

internetReachability = [Reachability reachabilityWithHostname:@"www.google.com"];
    // Internet is reachable
    internetReachability.reachableBlock = ^(Reachability*reach)
    {
        // Update the UI on the main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"Internet Connection Established");
            // Update accordingly, use Storyboards or Navigation Stack
        });
    };

    // Internet is not reachable
    internetReachability.unreachableBlock = ^(Reachability*reach)
    {
        // Update the UI on the main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            // Update accordingly, use Storyboards or Navigation Stack

        });
    };

    [internetReachability startNotifier];

关于ios - iOS应用程序启动时无法上网-继续重试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23340110/

10-12 00:16
查看更多