了解iOS设备是否具有蜂窝数据功能 [英] Know if iOS device has cellular data capabilities

查看:178
本文介绍了了解iOS设备是否具有蜂窝数据功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个切换,即仅在WiFi上下载。但是,切换对于iPod touch或WiFi-iPad来说毫无用处。

I have a toggle in my app that's "download on WiFi only". However, that toggle is useless for iPod touch or WiFi-iPads.

有没有办法知道设备是否具有代码中的蜂窝数据功能?未来有用的东西也会很棒(比如带有3G的iPod touch第5代)。

Is there a way to know if the device has cellular data capabilities in code? Something that would work in the future would be great too (like if an iPod touch 5th gen with 3G comes out).

推荐答案

您应该能够检查它是否具有pdp_ip0接口

Hi you should be able to check if it has the 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;
}

这不使用任何私有API。

This doesn't use any private APIs.

这篇关于了解iOS设备是否具有蜂窝数据功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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