确定iPhone互联网连接是否可用的最简单方法? [英] Easiest way to determine whether iPhone internet connection is available?

查看:110
本文介绍了确定iPhone互联网连接是否可用的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望确定iPhone上是否有互联网连接。对于应用程序来说无论是wifi还是EDGE或其他什么都无关紧要。

I am looking to determine whether an internet connection is available on the iPhone. It doesn't matter for the app whether it's wifi or EDGE or whatever.

使用SeismicXML示例中的代码似乎不起作用,而且Reachability示例代码来自Apple似乎对该应用程序有点过分...

Using the code from the SeismicXML example doesn't seem to work and the Reachability example code from Apple seems like overkill for the app...

有没有一种快速简便的方法来确定iPhone上的网络可用性?

Is there a quick and easy way to determine network availability on the iPhone?

谢谢,
Ben

Thanks, Ben

推荐答案

遵循以下3个简单步骤 -

步骤1:在项目中包含SystemConfiguration.framework框架

Step 1: Include "SystemConfiguration.framework" framework in your project

第2步:包含Apple的Reachability.h和Reachability.m来自可达性示例

Step 2: Included Apple's Reachability.h and Reachability.m from Reachability example

第3步:现在添加此项代码中任意位置的代码。

Step 3: Now add this code anywhere in your .m.

Reachability* wifiReach = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];

switch (netStatus)
{
    case NotReachable:
    {
        NSLog(@"Access Not Available");
        break;
    }

    case ReachableViaWWAN:
    {
        NSLog(@"Reachable WWAN");
        break;
    }
    case ReachableViaWiFi:
    {
        NSLog(@"Reachable WiFi");
        break;
    }
}

这篇关于确定iPhone互联网连接是否可用的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆