iOS UIDevice设备信息,传感器设置,横竖屏判断操作,手机电池操作

来源:互联网 发布:手机复制软件下载 编辑:程序博客网 时间:2024/05/16 15:54

1、UIDevice是设备的信息相关的类,里面包含了很多手机设备的信息,包括版本号,手机名字等等。

2、一些属性的简单介绍:

+ (UIDevice *)currentDevice; // 获取当前的唯一设备@property(nonatomic,readonly,strong) NSString    *name; // 只读属性,手机的名称,比如“My iPhone“@property(nonatomic,readonly,strong) NSString    *model; // 手机的模型 比如“iPhone“@property(nonatomic,readonly,strong) NSString    *localizedModel; // 本地化的模型@property(nonatomic,readonly,strong) NSString    *systemName; // 系统名称 比如“iOS“@property(nonatomic,readonly,strong) NSString    *systemVersion; // 系统版本号@property(nonatomic,readonly) UIDeviceOrientation orientation; // 当前设备的取向,横屏,竖屏,旋转屏幕的时候用到@property(nullable, nonatomic,readonly,strong) NSUUID      *identifierForVendor; // 设备的UUID唯一标示,注意上线产品不要获取,会被拒的@property(nonatomic,readonly,getter=isMultitaskingSupported) BOOL multitaskingSupported; // 是否支持多任务@property(nonatomic,readonly) UIUserInterfaceIdiom userInterfaceIdiom; // UI的显示样式,手机,iPad,TV

传感器设置

@property(nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled; // 是否开启距离传感器检测,默认为NO,@property(nonatomic,readonly) BOOL proximityState; // 当前设备的传感器开启状态,

横竖屏判断:

UIDeviceOrientationPortrait, // 竖屏UIDeviceOrientationPortraitUpsideDown, // 竖屏UIDeviceOrientationLandscapeLeft, // 横屏UIDeviceOrientationLandscapeRight, // 横屏BOOL UIDeviceOrientationIsPortrait(UIDeviceOrientation orientation) // 判断手机的当前屏幕是否是竖屏,用来做屏幕的旋转BOOL UIDeviceOrientationIsLandscape(UIDeviceOrientation orientation) // 判断手机的当前屏幕是否是横屏,用来做屏幕的旋转

手机电池操作

UIDeviceBatteryStateUnknown,UIDeviceBatteryStateUnplugged, // 没有充电UIDeviceBatteryStateCharging,  // 充电状态,未充满电UIDeviceBatteryStateFull, // 充满电@property(nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled; // 是否开启手机电池检测,默认NO,如果要获取手机电池的电量,状态等,需要打开设置开关@property(nonatomic,readonly) UIDeviceBatteryState          batteryState; // 手机电池的状态,充电中,未充电,已经充满等,如果电池的没有开启检测,默认返回UIDeviceBatteryStateUnknown@property(nonatomic,readonly) float                         batteryLevel; // 手机电量,要获取真实数据,必须打开电池检测,
0 0