1

嗨,我需要了解 iPhone 互联网是否连接 3G 或 2G 或 WIFI 网络有任何建议

谢谢

斯拉万

4

3 回答 3

8

从此链接下载适用于 iOS 的可达性类:- https://github.com/tonymillion/Reachability

1)在您的 Project 中添加 Reachability.h &.m,确保通过添加标志 -fno-objc-arc 使其与 ARC 兼容

2)现在,检查视图控制器中的连接类型

  Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];

    NetworkStatus status = [reachability currentReachabilityStatus];

    if(status == NotReachable) 
    {
        //No internet
    }
    else if (status == ReachableViaWiFi)
    {
        //WiFi
    }
    else if (status == ReachableViaWWAN) 
    {
        //3G
    }
于 2014-04-22T12:35:59.610 回答
2

您可以使用Reachabilitytonymillion 编写的库。如果你不想使用 ARC,还有 Apple Reachability 库。

于 2014-04-22T12:34:56.017 回答
1

还要看看 <CoreTelephony/CTTelephonyNetworkInfo.h > 的内部

您将看到 CTTelephonyNetworkInfo 上公开了 currentRadioAccessTechnology 属性。

CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
NSLog(@"Radio access technology:\n%@",
       netInfo.currentRadioAccessTechnology);

您可以通过以下方式订阅更改:

[NSNotificationCenter.defaultCenter
    addObserverForName:CTRadioAccessTechnologyDidChangeNotification
                object:nil
                 queue:nil
            usingBlock:^(NSNotification __unused *notification) {
                CTTelephonyNetworkInfo *current =
                    [[CTTelephonyNetworkInfo alloc] init];
                NSLog(@"Updated Radio access technology:\n%@",
                       current.currentRadioAccessTechnology);
            }];
于 2015-01-08T00:50:10.843 回答