如何获得ios 中的硬件信息(上)
2012-11-09 11:51
489 查看
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等信息,具体见下篇博文。
一。能够直接通过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 消息推送 点击app图标 app icon如何获取推送信息 leanCloud 点击app图标 获得推送消息
- 转:C#编程中如何获得硬件的信息
- iOS 开发 如何获得用户当前位置(通过经纬度获得城市、省份等信息)
- 如何获得ios设备的硬件名称
- iOS如何获取设备硬件信息
- IOS硬件信息采集汇总
- IOS硬件信息采集汇总
- Vickate_iOS_如何获取手机及应用的信息
- 如何获得运行在跨平台的信息和属性的情况下,文件
- .net中如何获取机器硬件信息(防软件复制版)
- 尝试EJB整合Mybatis部署时报错:获得带有类加载器MybatisUtil的ModuleClassLoader的反射信息出错,请问大神如何解决
- ios开发中如何修改AppStore中开发商的信息
- 如何获得listview选中行的信息
- 通过WMI获得硬件信息
- Linux如何查看硬件信息
- IOS开发第一步,由于先不买硬件,先找一下,如何用虚拟机装 mac osx
- 如何通过C#获取硬件信息。
- FCL小应用系列------------如何获取网卡等硬件信息
- iOS设备如何获得电池百分之一的比率