HappyCoding:] ChildhoodAndy

思维世界的发展,在某种意义上说,就是对惊奇的不断摆脱。——爱因斯坦

IOS获取设备信息常用方法记录

| Comments

1. 常用方法 GithubGist地址

常用方法
NSLog(@"HostName: %@", [[NSProcessInfo processInfo] hostName]);
//globallyUniqueString 唯一的标示符,每次调用都会不一样,可以用作一些临时缓存文件的名字
NSLog(@"GlobalUniqueString: %@", [[NSProcessInfo processInfo] globallyUniqueString]);
//操作系统名称
NSLog(@"OperatingSystemName: %@", [[NSProcessInfo processInfo] operatingSystemName]);
//操作系统版本
NSLog(@"OperatingSystemVersion: %@", [[NSProcessInfo processInfo] operatingSystemVersionString]);
//物理内存
NSLog(@"PhysicalMem: %llu", [[NSProcessInfo processInfo] physicalMemory]);
//进程名称
NSLog(@"ProcessName: %@", [[NSProcessInfo processInfo] processName]);

//供应商标识
NSLog(@"UniqueId: %@", [UIDevice currentDevice].identifierForVendor);
//设备类型(iPhone、iPad)
NSLog(@"userInterfaceIdiom: %d", [UIDevice currentDevice].userInterfaceIdiom);
//设备名字
NSLog(@"Name: %@", [UIDevice currentDevice].name);
//系统名字
NSLog(@"SystemName: %@", [UIDevice currentDevice].systemName);
//系统版本
NSLog(@"SystemVersion: %@", [UIDevice currentDevice].systemVersion);
//模型
NSLog(@"Model: %@", [UIDevice currentDevice].model);
//本地化的模型
NSLog(@"LocalizeModel: %@", [UIDevice currentDevice].localizedModel);
//电池状态
NSLog(@"BatteryLevel: %f", [UIDevice currentDevice].batteryLevel);

//2014-07-03 16:52:01.055 CityOfHeart[3528:60b] HostName: dounen
//2014-07-03 16:52:01.058 CityOfHeart[3528:60b] GlobalUniqueString: B4B1EC8C-A805-434B-9D57-106ED70C214A-3528-00000AF6A42D73D7
//2014-07-03 16:52:01.059 CityOfHeart[3528:60b] OperatingSystemName: NSMACHOperatingSystem
//2014-07-03 16:52:01.061 CityOfHeart[3528:60b] OperatingSystemVersion: Version 7.1.1 (Build 11D201)
//2014-07-03 16:52:01.063 CityOfHeart[3528:60b] PhysicalMem: 1035976704
//2014-07-03 16:52:01.064 CityOfHeart[3528:60b] ProcessName: CityOfHeart
//2014-07-03 16:52:01.074 CityOfHeart[3528:60b] UniqueId: <__NSConcreteUUID 0x16693c80> 5ACF8DA1-FAC1-4D70-AB1F-BB696188C5CA
//2014-07-03 16:52:01.075 CityOfHeart[3528:60b] userInterfaceIdiom: 0
//2014-07-03 16:52:01.157 CityOfHeart[3528:60b] Name: 童年
//2014-07-03 16:52:01.159 CityOfHeart[3528:60b] SystemName: iPhone OS
//2014-07-03 16:52:01.161 CityOfHeart[3528:60b] SystemVersion: 7.1.1
//2014-07-03 16:52:01.162 CityOfHeart[3528:60b] Model: iPad
//2014-07-03 16:52:01.163 CityOfHeart[3528:60b] LocalizeModel: iPad
//2014-07-03 16:52:01.165 CityOfHeart[3528:60b] BatteryLevel: -1.000000

2. 判断设备是否是7.0以上系统

[[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f

注意:
假如我们的设备版本号为7.1.1(为字符串类型),对其进行floatValue浮点化后值为7.100000

3. 判断设备是否是iPhone、iPad

  • iPad:[[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad
  • iPhone: [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
UIUserInterfaceIdiom in UIDevice.h
typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
#if __IPHONE_3_2 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    UIUserInterfaceIdiomPhone,           // iPhone and iPod touch style UI
    UIUserInterfaceIdiomPad,             // iPad style UI
#endif
};

Comments

comments powered by Disqus