iphone - 了解 iOS 设备是否具有蜂窝数据功能

标签 iphone objective-c ios uidevice cellular-network

我的应用程序中有一个开关“仅在 WiFi 上下载”。但是,该切换对 iPod touch 或 WiFi-iPad 毫无用处。

有没有办法在代码中知道设备是否具有蜂窝数据功能?将来可以使用的东西也会很棒(比如如果推出带有 3G 的 iPod touch 5th gen)。

最佳答案

您好,您应该能够检查它是否具有 pdp_ip0 接口(interface)

#import <ifaddrs.h>

- (bool) hasCellular {
    struct ifaddrs * addrs;
    const struct ifaddrs * cursor;
    bool found = false;
    if (getifaddrs(&addrs) == 0) {
        cursor = addrs;
        while (cursor != NULL) {
            NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
            if ([name isEqualToString:@"pdp_ip0"]) {
                found = true;
                break;
            }
            cursor = cursor->ifa_next;
        }
        freeifaddrs(addrs);
    }
    return found;
}

这不使用任何私有(private) API。

关于iphone - 了解 iOS 设备是否具有蜂窝数据功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7101206/

相关文章:

ios - 如何自动缩放不同分辨率的场景?

ios - 是否可以维护 iOS 应用程序的 'compatible' 版本

objective-c - MPMediaQuery artistsQuery 返回重复项

ios - 是否可以在不着色图标的情况下着色TabBar?

ios - 寻找用于创建复杂 UIBezierPath 的工具

ios - iPhone : How to detect the end of slider drag?

ios - tableView.reloadData() 每次 View 出现

C++ 到 Objective-C,在 for 循环中使用 const int

iphone - UIWebView 中的异步 HTTP 请求真的会产生新线程吗?

iphone - 将动态输入的数据保存到 plist