如何获得ios 中的硬件信息(上)
来源:互联网 发布:centos打开端口命令 编辑:程序博客网 时间:2024/05/12 15:13
ios 自身提供了UIDevice 的类给与我们获得一些硬件的属性。我们还可以通过一些其他的方法得到更多的信息。
一。能够直接通过UIDevice得到的属性有:
The device unique identifier
The name of the device
The localized version of the model of the device (iPhone, iPod Touch)
The system name (iPhone OS)
The system version (2.2.1, etc.)
The language and locale used on the device(en_US)
The short version of the time zone (MST)
实现的代码如下:
UIDevice *aDevice = [UIDevice currentDevice];
NSLocale *currentLocale = [NSLocale currentLocale];
NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSMutableArray *passingArray = [[NSMutableArray alloc] initWithCapacity:5];
[passingArray addObject: [aDevice uniqueIdentifier]];
[passingArray addObject: [aDevice name]];
[passingArray addObject: [aDevice localizedModel]];
[passingArray addObject: [aDevice systemName]];
[passingArray addObject: [aDevice systemVersion]];
[passingArray addObject: [defs objectForKey:@"AppleLocale"]];
NSString *timeZoneString = [timeZone localizedName:NSTimeZoneNameStyleShortStandard locale:currentLocale];
if([timeZone isDaylightSavingTimeForDate:[NSDate date]]){
timeZoneString = [timeZone localizedName:NSTimeZoneNameStyleShortDaylightSaving locale:currentLocale];
}
[passingArray addObject: timeZoneString];
The JavaScript to display this information, found in the functions.js file of the DeviceDescriptionExample, is seen here.
function displayDeviceInfoVCF(data, paramArray){
document.getElementById(‘devDisplay’).innerText = ‘UDID: ‘+paramArray[0]+‘\n\ndevice name: ‘+paramArray[1]+‘\n\nmodel: ‘+paramArray[2]
+‘\n\nsystem: ‘+paramArray[3]+‘\n\nOS version: ‘+paramArray[4]+‘\n\nLanguage and Locale: ‘+paramArray[5]+‘\n\nTimeZone: ‘+paramArray[6];
}
但是从ios5开始苹果官方不支持获取UniqueIndentifier(UDID) 的方法,原先的方法不管用了。苹果官方又推出了一种新的方法,获取UUID。
新方法的原理为在第一次使用程序的时候用CFUUIDCreate创造一个 UUID,然后将它存到NSUserDefault中,当做以前的UDID来用就行了。不过直接调用CFUUIDCreate得到的还不是一个直接的NSString,需要经过一些步骤才能转换成我们熟悉UDID形式。
具体的实现方法为:
CFUUIDRef deviceId = CFUUIDCreate (NULL);
CFStringRef deviceIdStringRef = CFUUIDCreateString(NULL,deviceId);
CFRelease(deviceId);
NSString *deviceIdString = (NSString *)deviceIdStringRef;
NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];
[standardUserDefault setValue:deviceIdString forKey:@"deviceId"];
[deviceIdString release];
[standardUserDefault synchronize];
关于CFUUIDCreate,在苹果文档上有说明:
CFUUIDCreate
Creates a Universally Unique Identifier (UUID) object.
CFUUIDRef CFUUIDCreate (
CFAllocatorRef alloc
);
但是这个方法有一个漏洞就是,在每次该应用重装以后,新的UUID都会改变。而且据网上资料说,UUID不能保证每次在系统升级后还能用。
而开发者获取UDID或者UUID的原因不外乎都是为了能够获得匹配设备的唯一标示。因此网上的最为可行的方法便是获取用户的mac地址,并且
对其进行加密。
具体的解决方法可以参照(下载地址):
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
除此之外,你还能获得其他的一些手机信息,如mac地址,序列号,IMEI等信息,具体见下篇博文。- 如何获得ios 中的硬件信息(上)
- 如何获得ios设备中的硬件信息(下)
- 如何获得ios设备的硬件名称
- 学习获得硬件信息
- iOS如何获取设备硬件信息
- 转:C#编程中如何获得硬件的信息
- 如何获得Http Request中的信息
- 通过WMI获得硬件信息
- 获得本机硬件信息
- wmic 获得系统硬件信息
- 如何在Linux上使用命令行查看硬件信息
- IOS 硬件信息对应
- ios获取硬件信息
- 获得ios设备信息
- 获得硬件信息的有关文章
- 获得PC的系统和硬件信息
- PHP调用COM获得服务器硬件信息
- 获得android手机的硬件信息
- 第十周-贪财的富翁
- Java Web-JDBC
- 有关T-SQL的10个好习惯
- SolutionConverter
- 网站建设中兼容问题css样式
- 如何获得ios 中的硬件信息(上)
- 我的第二十四个C++上机报告(穷举法解决组合问题之百钱百鸡问题)
- 几种常用的视频接口
- 最小公倍数与最大公约数
- 输入一个正整数,判断其是否为素数
- SSLException
- JDB常用命令
- org.apache.axis.ConfigurationException: No service named ldapOperate is available解决方法
- tcpdump高级过滤表达式