UIDevice [设备]
继承:NSObject
UIDevice 类提供了一个单例实例代表当前的设备。从这个单例中可以获取设备名称、设备模型和操作系统名称和版本等设备信息。
[UIDevice currentDevice]
你也可以使用UIDevice实例检测设备变化的特点,例如设备方向。
你要获得当前方向的属性或接收改变通知需要注册 UIDeviceOrientationDidChangeNotification 通知。
在你需要使用这些通知来获取方向数据时,必须使用 beginGeneratingDeviceOrientationNotifications 方法。
当你不再需要跟踪设备方向时,你得调用 endGeneratingDeviceOrientationNotifications 方法。
类似地,你可以使用UIDevice实例获取关于电池状态更改(batteryState属性所描述)和电量(batteryLevel 属性所描述)的信息和通知。UIDevice实例还提供了访问距离传感器状态(proximityState 属性所描述)。距离传感器检测用户是否持有设备靠近自己的脸。只有当你实现它的时候,才能实现 电池监视或接近报警。
你还可以使用 playInputClick 实例方法获取键盘输入点击和自定义键盘辅助视图。
获得共享设备实例
-
- + (UIDevice *)currentDevice;
确定可用的特性
-
- @property(nonatomic, readonly, getter=isMultitaskingSupported) BOOL multitaskingSupported;
识别设备和操作系统
-
- @property(nonatomic, readonly, strong) NSString *name;
-
-
- @property(nonatomic, readonly, strong) NSString *systemName;
-
-
- @property(nonatomic, readonly, strong) NSString *systemVersion;
-
-
- @property(nonatomic, readonly, strong) NSString *model;
-
-
- @property(nonatomic, readonly, strong) NSString *localizedModel;
-
-
- @property(nonatomic, readonly) UIUserInterfaceIdiom userInterfaceIdiom;
-
-
- @property(nonatomic, readonly, strong) NSUUID *identifierForVendor;
获取设备方向
-
- @property(nonatomic, readonly) UIDeviceOrientation orientation;
-
-
- @property(nonatomic, readonly, getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications;
-
-
- - (void)beginGeneratingDeviceOrientationNotifications;
-
-
- - (void)endGeneratingDeviceOrientationNotifications;
获取设备的电池状态
-
- @property(nonatomic, readonly) float batteryLevel;
-
-
- @property(nonatomic, getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled;
-
-
- @property(nonatomic, readonly) UIDeviceBatteryState batteryState;
使用近距离传感器
-
- @property(nonatomic, getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled;
-
-
- @property(nonatomic, readonly) BOOL proximityState;
输入点击
常量
1、UIDeviceBatteryState电池供电的设备状态。
- typedef enum {
-
- UIDeviceBatteryStateUnknown,
-
-
- UIDeviceBatteryStateUnplugged,
-
-
- UIDeviceBatteryStateCharging,
-
-
- UIDeviceBatteryStateFull,
- } UIDeviceBatteryState;
2、UIDeviceOrientation 物理设备方向
- typedef enum {
-
- UIDeviceOrientationUnknown,
-
-
- UIDeviceOrientationPortrait,
-
-
- UIDeviceOrientationPortraitUpsideDown,
-
-
- UIDeviceOrientationLandscapeLeft,
-
-
- UIDeviceOrientationLandscapeRight,
-
-
- UIDeviceOrientationFaceUp,
-
-
- UIDeviceOrientationFaceDown
- } UIDeviceOrientation;
3、UIUserInterfaceIdiom
应该使用的接口的类型对当前设备
- typedef enum {
-
- UIUserInterfaceIdiomUnspecified = -1
-
-
- UIUserInterfaceIdiomPhone,
-
-
- UIUserInterfaceIdiomPad,
-
-
- UIUserInterfaceIdiomTV,
-
-
- UIUserInterfaceIdiomCarPlay,
- } UIUserInterfaceIdiom;
可用通知
1、UIDeviceBatteryLevelDidChangeNotification 电池改变通知
2、UIDeviceOrientationDidChangeNotification 设备方向改变通知
3、UIDeviceProximityStateDidChangeNotification 传感器状态发生改变通知
写于 2017-3-2,特此记录,备忘