获取设备和 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 }
时间: 2024-12-15 03:03:47

获取设备和 App 信息的相关文章

获取设备、APP的一些信息

获取设备的一些信息: UIDevice *device = [UIDevice currentDevice]; @property(nonatomic,readonly,strong) NSString *name;              // e.g. "My iPhone" @property(nonatomic,readonly,strong) NSString *model;             // e.g. @"iPhone", @"i

IOS获取设备及App相应信息

iOS的SDK中提供了UIDevice,NSBundle,NSLocale,UIScreen等类来获取设备.app等相应的信息. UIDevice用于获取设备相应的信息,如设备名称.设备唯一标识.系统名称.系统版本号.设备模式.本地设备模式等. NSBundle用于获取App相应的信息,如应用名称.应用版本.应用Build版本等. NSLocale用于获取用户的本地化信息设置,例如货币类型,国家,语言,数字,日期格式的格式化,提供正确的地理位置显示等. UIScreen用于获取设备的屏幕尺寸和分

C#:获取设备电量相关信息

[DllImport("kernel32.dll",EntryPoint="GetSystemPowerStatus")] //win32 api private static extern void GetSystemPowerStatus(ref SYSTEM_POWER_STATUS lpSystemPowerStatus); public struct SYSTEM_POWER_STATUS //结构体 { public Byte ACLineStatus;

iOS ---------- 获取设备的各种信息

一.目录结构: 获取屏幕宽度与高度 获取设备版本号 获取iPhone名称 获取app版本号 获取电池电量 获取当前系统名称 获取当前系统版本号 获取通用的唯一识别码UUID 获取当前设备IP 获取总内存大小 获取当前可用内存 获取精准电池电量 获取电池当前的状态(共有4种状态) 获取设备当前的语言 二.具体内容 1. 获取屏幕宽度与高度 /// 屏幕宽度 + (CGFloat)getDeviceScreenWidth { return [UIScreen mainScreen].bounds.s

iOS 获取设备的各种信息的方法

一.目录结构: 获取屏幕宽度与高度 获取设备版本号 获取iPhone名称 获取app版本号 获取电池电量 获取当前系统名称 获取当前系统版本号 获取通用的唯一识别码UUID 获取当前设备IP 获取总内存大小 获取当前可用内存 获取精准电池电量 获取电池当前的状态(共有4种状态) 获取设备当前的语言 二.具体内容 1. 获取屏幕宽度与高度 1 2 3 4 5 6 7 8 /// 屏幕宽度 + (CGFloat)getDeviceScreenWidth {     return [UIScreen 

使用phonegap获取设备的一些信息

device.name   设备的名称device.phonegap   phonegap版本device.platform  设备的类型device.uuid  设备唯一识别号device.version  所运行的操作系统的版本device是被指派给window对象的 <!DOCTYPE html>   <html>          <head>           <meta charset="UTF-8">           

iOS 随笔小技巧 弱self 打印当前类行数列数,多人开发自动适配pch地址,获取设备uid的信息

$(SRCROOT)/PrefixHeader.pch自动适配pch地址 __weak __block typeof(self) weakself = self; __weak typeof(self)weakSelf = self; #define DN_DEBUG_LOG(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); } NSDictionary *if

[iOS]获取设备具体型号信息

本文地址; http://blog.csdn.net/zhaoyabei/article/details/46697859 应用统计中有时候需要上传设备型号,如果这样写: [[UIDevice currentDevice] model] 获得的设备型号不是具体型号,如在iPhone5S上面运行,实测得到字符串为@"iPhone",我想要的是具体型号. 这里提供一个方法来获得设备具体型号(版本与机型的对应关系来源于维基百科): - (NSString *)platform{ struct

Android开发之获取设备的屏幕信息

1 DisplayMetrics metric = new DisplayMetrics(); 2 getWindowManager().getDefaultDisplay().getMetrics(metric); 3 int width = metric.widthPixels; // 屏幕宽度(像素) 4 int height = metric.heightPixels; // 屏幕高度(像素) 5 float density = metric.density; // 屏幕密度(0.75