我有一个要求,比如我需要以编程方式找到,具有GSM,CDMA和SPI网络能力的IOS设备。
所以,如果有任何方法可以找到,请告诉我。
先谢谢。
答案 0 :(得分:0)
使用UIDevice
课程,您可以确定您的应用程序是在iPod还是iPhone上运行。要获取此信息,请访问名为model的属性,该属性将返回iPhone或iPod touch的NSString。但是,有时候你需要更多细节,例如iPhone是最新的设备,3GS还是另一方面,iPod是第一代还是第二代设备?
访问系统硬件将揭示我们做出上述区分所需的信息。我们将使用一个类别来扩展UIDevice类,该方法将“machine”类型作为字符串返回。从下面的接口定义开始:
@interface UIDevice(machine)
- (NSString *)machine;
@end
要访问硬件类型,我们将调用标准C库中的函数:
sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
或强>
导入#import <sys/utsname.h>
然后,NSString *deviceName = [Classname myDeviceModel];
+ (NSString*)myDeviceModel
{
struct utsname deviceInfo;
uname(&deviceInfo);
NSString *deviceNameTemp = [NSString stringWithCString:deviceInfo.machine encoding:NSUTF8StringEncoding];
NSDictionary *deviceDictionary =
@{
//simulators.
@"i386": @"iPhone Simulator",
@"x86_64": @"iPad Simulator",
//iPhone's.
@"iPhone1,1": @"iPhone",
@"iPhone1,2": @"iPhone 3G",
@"iPhone2,1": @"iPhone 3GS",
@"iPhone3,1": @"iPhone 4",
@"iPhone3,2": @"iPhone 4(Rev A)",
@"iPhone3,3": @"iPhone 4(CDMA)",
@"iPhone4,1": @"iPhone 4S",
@"iPhone5,1": @"iPhone 5(GSM)",
@"iPhone5,2": @"iPhone 5(GSM+CDMA)",
@"iPhone5,3": @"iPhone 5c(GSM)",
@"iPhone5,4": @"iPhone 5c(GSM+CDMA)",
@"iPhone6,1": @"iPhone 5s(GSM)",
@"iPhone6,2": @"iPhone 5s(GSM+CDMA)",
//iPads.
@"iPad1,1": @"iPad",
@"iPad2,1": @"iPad 2(WiFi)",
@"iPad2,2": @"iPad 2(GSM)",
@"iPad2,3": @"iPad 2(CDMA)",
@"iPad2,4": @"iPad 2(WiFi Rev A)",
@"iPad2,5": @"iPad Mini(WiFi)",
@"iPad2,6": @"iPad Mini(GSM)",
@"iPad2,7": @"iPad Mini(GSM+CDMA)",
@"iPad3,1": @"iPad 3(WiFi)",
@"iPad3,2": @"iPad 3(GSM+CDMA)",
@"iPad3,3": @"iPad 3(GSM)",
@"iPad3,4": @"iPad 4(WiFi)",
@"iPad3,5": @"iPad 4(GSM)",
@"iPad3,6": @"iPad 4(GSM+CDMA)",
//ipods
@"iPod1,1": @"iPod 1st Gen",
@"iPod2,1": @"iPod 2nd Gen",
@"iPod3,1": @"iPod 3rd Gen",
@"iPod4,1": @"iPod 4th Gen",
@"iPod5,1": @"iPod 5th Gen",
};
NSString *deviceName = commonNamesDictionary[deviceNameTemp];
if (deviceName == nil)
{
deviceName = machineName;
}
return deviceName;
}