我的应用程序中有一个开关“仅在 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/