获取设备和 App 信息

设备对照表:https://www.theiphonewiki.com/wiki/Models

获取设备和 App 信息代码:

 1     NSLog(@"设备信息如下");
 2     NSLog(@"detailModel(详细型号): %@", [self detailModel]); //detailModel(详细型号): iPhone 6
 3     
 4     UIDevice *device = [UIDevice currentDevice];
 5     NSLog(@"name(名称): %@", [device name]); //name(名称): My iPhone
 6     NSLog(@"model(型号): %@", [device model]); //model(型号): iPhone
 7     NSLog(@"localizedModel(本地化型号): %@", [device localizedModel]); //localizedModel(本地化型号): iPhone
 8     NSLog(@"systemName(系统名称): %@", [device systemName]); //systemName(系统名称): iPhone OS
 9     NSLog(@"systemVersion(系统版本): %@", [device systemVersion]); //systemVersion(系统版本): 8.3
10     NSLog(@"identifierForVendor(UUID): %@", [device identifierForVendor]); //identifierForVendor(UUID): <__NSConcreteUUID 0x7ff21b5c8410> 1F61341F-26B2-419C-8B35-75E8F1097CBD
11     
12     
13     NSLog(@"App信息如下");
14     NSDictionary *dicAppInfo = [[NSBundle mainBundle] infoDictionary];
15     NSString *shortVersion = [dicAppInfo objectForKey:@"CFBundleShortVersionString"];
16     NSString *buildVersion = [dicAppInfo objectForKey:@"CFBundleVersion"];
17     NSString *name = [dicAppInfo objectForKey:@"CFBundleName"];
18     NSString *displayName = [dicAppInfo objectForKey:@"CFBundleDisplayName"];
19     NSString *identifier = [dicAppInfo objectForKey:@"CFBundleIdentifier"];
20     NSString *minimumOSVersion = [dicAppInfo objectForKey:@"MinimumOSVersion"];
21     
22     NSLog(@"CFBundleShortVersionString(Version版本): %@", shortVersion); //CFBundleShortVersionString(Version版本): 1.0
23     NSLog(@"CFBundleVersion(Build版本): %@", buildVersion); //CFBundleVersion(Build版本): 1
24     NSLog(@"CFBundleName(名称): %@", name); //CFBundleName(名称): FirstBook187
25     NSLog(@"CFBundleDisplayName(显示名称): %@", displayName); //CFBundleDisplayName(显示名称): (null);默认为null,因为Info.plist文件默认不会添加“Bundle display name”,而App的显示名称优先级来说:CFBundleDisplayName>CFBundleName,即CFBundleDisplayName不存在的情况下,就是显示CFBundleName
26     NSLog(@"CFBundleIdentifier(标识符): %@", identifier); //CFBundleIdentifier(标识符): com.kenmu.FirstBook187
27     NSLog(@"MinimumOSVersion(兼容的最小操作系统版本): %@", minimumOSVersion); //MinimumOSVersion(兼容的最小操作系统版本): 7.0
28     
29     CFShow((__bridge CFTypeRef)(dicAppInfo)); //通过CFShow可以输出dicAppInfo的所有键值对信息;真机输出的信息比模拟器多

获取设备详细型号的代码:

 1 #import "sys/utsname.h"
 2 
 3 - (NSString *)detailModel {
 4     //{代号 : 详细型号}
 5     NSDictionary *dicDeviceInfo = @{ @"x86_64" : @"Simulator",
 6                                      @"i386" : @"Simulator",
 7                                      @"iPhone7,2" : @"iPhone 6",
 8                                      @"iPhone7,1" : @"iPhone 6 Plus",
 9                                      @"iPhone6,2" : @"iPhone 5s (Global)",
10                                      @"iPhone6,1" : @"iPhone 5s (GSM)",
11                                      @"iPhone5,4" : @"iPhone 5c (Global)",
12                                      @"iPhone5,3" : @"iPhone 5c (GSM)",
13                                      @"iPhone5,2" : @"iPhone 5 (GSM+CDMA)",
14                                      @"iPhone5,1" : @"iPhone 5 (GSM)",
15                                      @"iPhone4,1" : @"iPhone 4S",
16                                      @"iPhone3,3" : @"iPhone 4 (CDMA)",
17                                      @"iPhone3,2" : @"iPhone 4 (GSM Rev A)",
18                                      @"iPhone3,1" : @"iPhone 4 (GSM)",
19                                      @"iPhone2,1" : @"iPhone 3GS",
20                                      @"iPhone1,2" : @"iPhone 3G",
21                                      @"iPhone1,1" : @"iPhone 2G",
22                                      
23                                      @"iPad5,4" : @"iPad Air 2",
24                                      @"iPad5,3" : @"iPad Air 2",
25                                      @"iPad4,3" : @"iPad Air",
26                                      @"iPad4,2" : @"iPad Air",
27                                      @"iPad3,6" : @"iPad 4 (GSM+CDMA)",
28                                      @"iPad3,5" : @"iPad 4 (GSM)",
29                                      @"iPad3,4" : @"iPad 4 (WiFi)",
30                                      @"iPad3,3" : @"iPad 3 (GSM)",
31                                      @"iPad3,2" : @"iPad 3 (GSM+CDMA)",
32                                      @"iPad3,1" : @"iPad 3 (WiFi)",
33                                      @"iPad2,4" : @"iPad 2 (WiFi + New Chip)",
34                                      @"iPad2,3" : @"iPad 2 (CDMA)",
35                                      @"iPad2,2" : @"iPad 2 (GSM)",
36                                      @"iPad2,1" : @"iPad 2 (WiFi)",
37                                      @"iPad1,1" : @"iPad",
38                                      
39                                      @"iPad4,9" : @"iPad mini 3",
40                                      @"iPad4,8" : @"iPad mini 3",
41                                      @"iPad4,7" : @"iPad mini 3",
42                                      @"iPad4,6" : @"iPad mini 2",
43                                      @"iPad4,5" : @"iPad mini 2",
44                                      @"iPad4,4" : @"iPad mini 2",
45                                      @"iPad2,7" : @"iPad mini 1G (WiFi)",
46                                      @"iPad2,6" : @"iPad mini 1G (GSM)",
47                                      @"iPad2,5" : @"iPad mini 1G (GSM+CDMA)",
48                                      
49                                      @"iPod5,1" : @"iPod touch 5G",
50                                      @"iPod4,1" : @"iPod touch 4G",
51                                      @"iPod3,1" : @"iPod touch 3G",
52                                      @"iPod2,1" : @"iPod touch 2G",
53                                      @"iPod1,1" : @"iPod touch",
54                                      
55                                      @"Watch1,2" : @"Apple Watch",
56                                      @"Watch1,1" : @"Apple Watch",
57                                      
58                                      @"AppleTV3,2" : @"Apple TV 3G",
59                                      @"AppleTV3,1" : @"Apple TV 3G",
60                                      @"AppleTV2,1" : @"Apple TV 2G" };
61     struct utsname systemInfo; //这是LINUX系统放硬件版本的信息的地方;所以需要导入包sys/utsname.h
62     uname(&systemInfo);
63     NSString *strMachineCode = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
64     
65     //也可以用allKeys和indexOfObject结合,来判断是否此设备代号存在,再获取它对应的详细型号
66     NSString *strDetailModel = [dicDeviceInfo objectForKey:strMachineCode];
67     if(!strDetailModel) {
68         strDetailModel = @"Unknown Device";
69     }
70     return strDetailModel;
71 }

结果:

 1 2015-06-14 19:25:10.315 FirstBook187[2926:150270] 设备信息如下
 2 2015-06-14 19:25:10.316 FirstBook187[2926:150270] detailModel(详细型号): Simulator
 3 2015-06-14 19:25:10.316 FirstBook187[2926:150270] name(名称): iPhone Simulator
 4 2015-06-14 19:25:10.316 FirstBook187[2926:150270] model(型号): iPhone Simulator
 5 2015-06-14 19:25:10.316 FirstBook187[2926:150270] localizedModel(本地化型号): iPhone Simulator
 6 2015-06-14 19:25:10.317 FirstBook187[2926:150270] systemName(系统名称): iPhone OS
 7 2015-06-14 19:25:10.317 FirstBook187[2926:150270] systemVersion(系统版本): 8.3
 8 2015-06-14 19:25:10.317 FirstBook187[2926:150270] identifierForVendor(UUID): <__NSConcreteUUID 0x7fbc5365b290> 1F61341F-26B2-419C-8B35-75E8F1097CBD
 9 2015-06-14 19:25:10.318 FirstBook187[2926:150270] App信息如下
10 2015-06-14 19:25:10.318 FirstBook187[2926:150270] CFBundleShortVersionString(Version版本): 1.0
11 2015-06-14 19:25:10.318 FirstBook187[2926:150270] CFBundleVersion(Build版本): 1
12 2015-06-14 19:25:10.318 FirstBook187[2926:150270] CFBundleName(名称): FirstBook187
13 2015-06-14 19:25:10.318 FirstBook187[2926:150270] CFBundleDisplayName(显示名称): (null)
14 2015-06-14 19:25:10.376 FirstBook187[2926:150270] CFBundleIdentifier(标识符): com.kenmu.FirstBook187
15 2015-06-14 19:25:10.376 FirstBook187[2926:150270] MinimumOSVersion(兼容的最小操作系统版本): 7.0
16 <CFBasicHash 0x7fbc53504d60 [0x101ad8180]>{type = mutable dict, count = 21,
17 entries =>
18     1 : <CFString 0x7fbc535048d0 [0x101ad8180]>{contents = "CFBundleName"} = <CFString 0x7fbc53504d40 [0x101ad8180]>{contents = "FirstBook187"}
19     2 : <CFString 0x7fbc535030c0 [0x101ad8180]>{contents = "DTSDKName"} = <CFString 0x7fbc53504c90 [0x101ad8180]>{contents = "iphonesimulator8.3"}
20     3 : <CFString 0x101ab0b40 [0x101ad8180]>{contents = "CFBundleInfoPlistURL"} = <CFURL 0x7fbc53503e70 [0x101ad8180]>{string = Info.plist, encoding = 134217984
21     base = <CFURL 0x7fbc53503610 [0x101ad8180]>{string = file:///Users/Kenmu/Library/Developer/CoreSimulator/Devices/85240D3B-7BE5-4AF1-A570-F2116C2B7979/data/Containers/Bundle/Application/7FCB8335-0BD8-4A70-B0CC-17D8512FA327/FirstBook187.app/, encoding = 134217984, base = (null)}}
22     4 : <CFString 0x101ab0b80 [0x101ad8180]>{contents = "CFBundleNumericVersion"} = <CFNumber 0xb000000010080002 [0x101ad8180]>{value = +16809984, type = kCFNumberSInt32Type}
23     5 : <CFString 0x7fbc535046c0 [0x101ad8180]>{contents = "UILaunchStoryboardName"} = <CFString 0x7fbc53504a00 [0x101ad8180]>{contents = "LaunchScreen"}
24     11 : <CFString 0x7fbc53504880 [0x101ad8180]>{contents = "CFBundleDevelopmentRegion"} = <CFString 0x7fbc53504cc0 [0x101ad8180]>{contents = "en"}
25     12 : <CFString 0x7fbc53503e00 [0x101ad8180]>{contents = "CFBundleVersion"} = <CFString 0x7fbc535049e0 [0x101ad8180]>{contents = "1"}
26     15 : <CFString 0x7fbc53503e40 [0x101ad8180]>{contents = "DTPlatformName"} = <CFString 0x7fbc53504c60 [0x101ad8180]>{contents = "iphonesimulator"}
27     16 : <CFString 0x7fbc53504850 [0x101ad8180]>{contents = "CFBundlePackageType"} = <CFString 0x7fbc53504c40 [0x101ad8180]>{contents = "APPL"}
28     17 : <CFString 0x7fbc53503dd0 [0x101ad8180]>{contents = "UIMainStoryboardFile"} = <CFString 0x7fbc535049c0 [0x101ad8180]>{contents = "Main"}
29     18 : <CFString 0x7fbc535047f0 [0x101ad8180]>{contents = "CFBundleSupportedPlatforms"} = <CFArray 0x7fbc53504bc0 [0x101ad8180]>{type = mutable-small, count = 1, values = (
30     0 : <CFString 0x7fbc53504b90 [0x101ad8180]>{contents = "iPhoneSimulator"}
31 )}
32     19 : <CFString 0x7fbc53504750 [0x101ad8180]>{contents = "CFBundleShortVersionString"} = <CFString 0x7fbc53504a40 [0x101ad8180]>{contents = "1.0"}
33     23 : <CFString 0x7fbc53503da0 [0x101ad8180]>{contents = "CFBundleInfoDictionaryVersion"} = <CFString 0x7fbc535049a0 [0x101ad8180]>{contents = "6.0"}
34     24 : <CFString 0x7fbc53503bb0 [0x101ad8180]>{contents = "UIRequiredDeviceCapabilities"} = <CFArray 0x7fbc53504910 [0x101ad8180]>{type = mutable-small, count = 1, values = (
35     0 : <CFString 0x7fbc535048f0 [0x101ad8180]>{contents = "armv7"}
36 )}
37     25 : <CFString 0x7fbc535046f0 [0x101ad8180]>{contents = "CFBundleExecutable"} = <CFString 0x7fbc53504a20 [0x101ad8180]>{contents = "FirstBook187"}
38     27 : <CFString 0x7fbc535047c0 [0x101ad8180]>{contents = "MinimumOSVersion"} = <CFString 0x7fbc53504b70 [0x101ad8180]>{contents = "7.0"}
39     28 : <CFString 0x7fbc53503d70 [0x101ad8180]>{contents = "CFBundleIdentifier"} = <CFString 0x7fbc53504970 [0x101ad8180]>{contents = "com.kenmu.FirstBook187"}
40     29 : <CFString 0x7fbc535048b0 [0x101ad8180]>{contents = "UIDeviceFamily"} = <CFArray 0x7fbc53504ce0 [0x101ad8180]>{type = mutable-small, count = 1, values = (
41     0 : <CFNumber 0xb000000000000013 [0x101ad8180]>{value = +1, type = kCFNumberSInt64Type}
42 )}
43     30 : <CFString 0x7fbc53504820 [0x101ad8180]>{contents = "CFBundleSignature"} = <CFString 0x7fbc53504c20 [0x101ad8180]>{contents = "????"}
44     32 : <CFString 0x7fbc53504720 [0x101ad8180]>{contents = "LSRequiresIPhoneOS"} = <CFBoolean 0x101ad8bf0 [0x101ad8180]>{value = true}
45     33 : <CFString 0x7fbc53504780 [0x101ad8180]>{contents = "UISupportedInterfaceOrientations"} = <CFArray 0x7fbc53504b10 [0x101ad8180]>{type = mutable-small, count = 3, values = (
46     0 : <CFString 0x7fbc53504a60 [0x101ad8180]>{contents = "UIInterfaceOrientationPortrait"}
47     1 : <CFString 0x7fbc53504a90 [0x101ad8180]>{contents = "UIInterfaceOrientationLandscapeLeft"}
48     2 : <CFString 0x7fbc53504ad0 [0x101ad8180]>{contents = "UIInterfaceOrientationLandscapeRight"}
49 )}
50 }
原文地址:https://www.cnblogs.com/huangjianwu/p/4575555.html