IOS
获取设备信息一般是通过UIDevice,UIScreen,NSBundle,NSLocal等方式,如果说要获取设备的内存、处理器信息,似乎可以依照Unix获取类似信息方式。
UIDevice提供了多种属性、类函数及状态通知,包括检测电池电量和定位设备与临近感应,UIDevice所做的工作就是为应用程序提供用户及设备的一些信息。UIDevice类还能够收集关于设备的各种具体细节,例如机型及iOS版本等。其中大部分属性都对开发工作具有积极的辅助作用
代码示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
- (
void
) getDeviceInfo
{
UIDevice* curDev = [UIDevice currentDevice];
/** 设备系统信息*/
// 设备名称
NSLog(@
"\tname : %@"
, curDev.name);
// 设备模式
NSLog(@
"\tmodel : %@"
, curDev.model);
// 设备本地模式
NSLog(@
"\tlocalize : %@"
, curDev.localizedModel);
// 系统名称
NSLog(@
"\tos name : %@"
, curDev.systemName);
// 系统版本号
NSLog(@
"\tos version : %@"
, curDev.systemVersion);
// 设备类别:手机,平板电脑
switch
(curDev.userInterfaceIdiom)
{
case
UIUserInterfaceIdiomPhone:
NSLog(@
"\tIdiom : iPhone"
);
break
;
case
UIUserInterfaceIdiomPad:
NSLog(@
"\tIdiom : iPad"
);
break
;
default
:
NSLog(@
"\tIdiom : Unknow"
);
break
;
}
// 设备唯一标识
NSLog(@
"\tUUID : %@"
, curDev.identifierForVendor.UUIDString);
/** 设备方向 */
// 设备朝向
switch
(curDev.orientation)
{
case
UIDeviceOrientationPortrait:
NSLog(@
"\torientation : Portrait"
);
break
;
case
UIDeviceOrientationPortraitUpsideDown:
NSLog(@
"\torientation : upside down"
);
break
;
case
UIDeviceOrientationLandscapeLeft:
NSLog(@
"\torientation : left"
);
break
;
case
UIDeviceOrientationLandscapeRight:
NSLog(@
"\torientation : right"
);
break
;
case
UIDeviceOrientationFaceUp:
NSLog(@
"\torientation : face up"
);
break
;
case
UIDeviceOrientationFaceDown:
NSLog(@
"\torientation : face down"
);
break
;
default
:
NSLog(@
"\torientation : Unknow"
);
break
;
}
UIScreen* mainScreen = [UIScreen mainScreen];
// 屏幕尺寸
NSLog(@
"screen size : %.0fx%.0f"
, mainScreen.bounds.size.width, mainScreen.bounds.size.height);
/** 设备电池 */
NSLog(@
"Battery infomation"
);
// 电量
NSLog(@
"\tlevel : %.2f%%"
, curDev.batteryLevel*
100
);
switch
(curDev.batteryState)
{
case
UIDeviceBatteryStateUnplugged:
NSLog(@
"\tstate : Unplugged"
);
break
;
case
UIDeviceBatteryStateCharging:
NSLog(@
"\tstate : Charging"
);
break
;
case
UIDeviceBatteryStateFull:
NSLog(@
"\tstate : Full"
);
break
;
default
:
NSLog(@
"\tstate : Unknow"
);
break
;
}
// 电池监视器是否开启
if
( curDev.isBatteryMonitoringEnabled )
{
NSLog(@
"\tmonitor on : YES"
);
}
else
{
NSLog(@
"\tmonitor on : NO"
);
}
/** 体感器 */
NSLog(@
"Proximity Sensor infomation"
);
if
( curDev.proximityState )
{
NSLog(@
"\tsensor on : YES"
);
}
else
{
NSLog(@
"\tsensor on : NO"
);
}
if
(curDev.proximityMonitoringEnabled)
{
NSLog(@
"\tmonitor on : YES"
);
}
else
{
NSLog(@
"\tmonitor on : NO"
);
}
}
- (
void
) getBundleInfo
{
NSBundle* bundle = [NSBundle mainBundle];
NSDictionary* bundleInfo = [bundle infoDictionary];
// 应用信息
NSLog(@
"%@"
, bundleInfo);
/*
CFBundleDevelopmentRegion = en;
CFBundleExecutable = DeviceInfo;
CFBundleIdentifier = "arbboter.com.DeviceInfo";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleInfoPlistURL = "Info.plist -- file:///../DeviceInfo.app/";
CFBundleName = DeviceInfo;
CFBundleNumericVersion = 16809984;
CFBundlePackageType = APPL;
CFBundleShortVersionString = "1.0";
CFBundleSignature = "????";
CFBundleSupportedPlatforms = (
iPhoneSimulator
);
CFBundleVersion = 1;
DTPlatformName = iphonesimulator;
DTSDKName = "iphonesimulator8.1";
LSRequiresIPhoneOS = 1;
UIDeviceFamily = (
1
);
UILaunchStoryboardName = LaunchScreen;
UIMainStoryboardFile = Main;
UIRequiredDeviceCapabilities = (
armv7
);
UISupportedInterfaceOrientations = (
UIInterfaceOrientationPortrait,
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight
);
*/
}
|