iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备、系统信息、应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发api可以获取到的。那么通过那些api可以获取这些信息呢,iOS的SDK中提供了UIDevice,NSBundle,NSLocale。UIDevice
UIDevice提供了多种属性、类函数及状态通知,帮助我们全方位了解设备状况。从检测电池电量到定位设备与临近感应,UIDevice所做的工作就是为应用程序提供用户及设备的一些信息。UIDevice类还能够收集关于设备的各种具体细节,例如机型及iOS版本等。其中大部分属性都对开发工作具有积极的辅助作用。下面的代码简单的使用UIDevice获取手机属性。
//设备相关信息的获取
NSString *strName = [[UIDevice currentDevice] name];
NSLog(@"设备名称:%@", strName);//e.g. "My iPhone"
NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"设备唯一标识:%@", strId);//UUID,5.0后不可用
NSString *strSysName = [[UIDevice currentDevice] systemName];
NSLog(@"系统名称:%@", strSysName);// e.g. @"iOS"
NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@"系统版本号:%@", strSysVersion);// e.g. @"4.0"
NSString *strModel = [[UIDevice currentDevice] model];
NSLog(@"设备模式:%@", strModel);// e.g. @"iPhone", @"iPod touch"
NSString *strLocModel = [[UIDevice currentDevice] localizedModel];
NSLog(@"本地设备模式:%@", strLocModel);// localized version of model
NSBundle
bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundle。通过这个路径可以获取到应用的信息,例如应用名、版本号等。
//app应用相关信息的获取
NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];
// CFShow(dicInfo);
NSString *strAppName = [dicInfo objectForKey:@"CFBundleDisplayName"];
NSLog(@"App应用名称:%@", strAppName);
NSString *strAppVersion = [dicInfo objectForKey:@"CFBundleShortVersionString"];
NSLog(@"App应用版本:%@", strAppVersion);
NSString *strAppBuild = [dicInfo objectForKey:@"CFBundleVersion"];
NSLog(@"App应用Build版本:%@", strAppBuild);
NSLocale
NSLocale可以获取用户的本地化信息设置,例如货币类型,国家,语言,数字,日期格式的格式化,提供正确的地理位置显示等等。下面的代码获取机器当前语言和国家代码。
//Getting the User’s Language
NSArray *languageArray = [NSLocale preferredLanguages];
NSString *language = [languageArray objectAtIndex:0];
NSLog(@"语言:%@", language);//en
NSLocale *locale = [NSLocale currentLocale];
NSString *country = [locale localeIdentifier];
NSLog(@"国家:%@", country); //en_US
* iOS入门群:83702688
* android开发进阶群:241395671
*/
参考:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSLocale_Class/Reference/Reference.html
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-accessing-device-data-with-uidevice-and-nslocale/
分享到:
相关推荐
IOS应用源码——获取当前硬件可用内存的例子UIDevice.zip
IOS应用源码——UIDevice2.rar
UIDevice类是一个单例,其唯一的实例( [UIDevice currentDevice] ) 代表了当前使用的设备。 通过这个实例,可以获得设备的相关信息(包括系统名称,版本号,设备模式等等)。 也可以使用使用该实例来监测设备的...
ios应用源码之获取当前硬件可用内存的例子uidevice .
UIDevice最常见的用法就是用来监测iOS设备的电量了,然后再实现电池状态通知非常方便,除此之外还有传感器等信息的获取,这里我们就来总结一下iOS App开发中通过UIDevice类获取设备信息的方法:
前两年IOS应用源码-主要是用于毕业设计学习的。
IOS应用源码之获取当前硬件可用内存的例子UIDevice .zip
20-iOS SDK使用指南:利用UIDevice/NSLocale访问设备数据 移动信息化 Informatization 22-BYOD:CIO的第二十二条军规 24-XTools谢亿民:移动信息化不是简单的云落地 开发工具 Tool 26-Mono for Android 4.2初探 ...
UIDevice-DisplayName displayName()返回iOS设备的友好名称,其中不包括特定的类型信息(即“ iPhone X”) displayName(includeType: true)返回iOS设备的友好名称,其中还包括设备类型(例如“ iPhone X(GSM)”)...
UIDevice 封装,更方便的获取设备信息,以及仿真设备。.zip,DeviceKit is a value-type replacement of UIDevice.
一句话获取ios设备唯一标示符,使用VFL语法添加约束 [[UIDevice currentDevice].identifierForVendor UUIDString]
iOS 2.0版本以后UIDevice提供一个获取设备唯一标识符的方法uniqueIdentifier,通过该方法我们可以获取设备的序列号,这个也是目前为止唯一可以确认唯一的标示符。好景不长,因为该唯一标识符与手机一一对应,苹果...
其中, UIDevice 有一个属性 model 只是用于获取 iOS 设备的类型,如 iPhone , iPod touch , iPad 等;而其另一个属性 name 表示当前设备的名称,由用户在设置》通用》关于》名称中设定,如 My iPhone , xxx 的 ...
个人总结,仅供参考;废话一句,全为二十。
MGCopyAnswer-From-UIDevice 如何从 UIDevice 类 PRIVATE API 获取设备信息
NSBundle NSData NSDate NSDictionary NSException NSFileManager NSObject NSSet NSString NSTimer NSURL UIKit UIBezierPath UIButton UIColor UIDevice UIImage UIImageView UILable UINavigationController ...
如何获取iphone的硬件版本以及系统信息,获取iphone的系统信息使用[UIDevice currentDevice]以及如何获取iphone的硬件版本
#define iOS10 ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0) NSString * urlString = @App-Prefs:root=WIFI; if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url...