当前位置: 首页 > news >正文

iOS UIDevice设备信息

识别设备和操作系统

//获得共享设备实例
open class var current: UIDevice { get }//识别设备的名称
open var name: String { get } // e.g. "My iPhone"//设备类型
open var model: String { get } // e.g. @"iPhone", @"iPod touch"//本地化设备类型
open var localizedModel: String { get } // localized version of model//操作系统名称
open var systemName: String { get } // e.g. @"iOS"//操作系统版本
open var systemVersion: String { get } // e.g. @"4.0"//是否支持多任务
open var isMultitaskingSupported: Bool { get }

设备方向

//返回设备的物理方向
open var orientation: UIDeviceOrientation { get }//是否开启面向设备的方向通知更改
open var isGeneratingDeviceOrientationNotifications: Bool { get }//开始面向设备的方向通知更改
open func beginGeneratingDeviceOrientationNotifications() // nestable//结束面向设备的方向通知更改
open func endGeneratingDeviceOrientationNotifications()
public enum UIDeviceOrientation : Int {case unknown = 0 //设备的方向不能确定case portrait = 1 //设备竖向朝上case portraitUpsideDown = 2 //设备竖向朝下case landscapeLeft = 3 //设备横向朝左case landscapeRight = 4 //设备横向朝右case faceUp = 5 //设备平放朝上case faceDown = 6 //设备平放朝下
}
extension UIDeviceOrientation {public var isPortrait: Bool { get }//竖向public var isLandscape: Bool { get }//横向public var isFlat: Bool { get }//平放public var isValidInterfaceOrientation: Bool { get }
}

设备方向监测 

//开启监听设备方向
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
//注册监听设备方向事件
NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil)
//关闭监听设备方向
UIDevice.current.endGeneratingDeviceOrientationNotifications()
//注销监听设备方向事件
NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
@objc func orientationDidChange() {//竖屏print("isPortrait", UIDevice.current.orientation.isPortrait)//横屏print("isLandscape", UIDevice.current.orientation.isLandscape)//平放print("isFlat", UIDevice.current.orientation.isFlat)//竖起print("isValidInterfaceOrientation", UIDevice.current.orientation.isValidInterfaceOrientation)
}

设备的电池状态

//电量
open var batteryLevel: Float { get }//电池状态
open var batteryState: UIDevice.BatteryState { get }//开启电池监测
open var isBatteryMonitoringEnabled: Bool

 UIDeviceBatteryState电池供电的设备状态

public enum BatteryState : Int {case unknown = 0    //设备的电池状态不能确定case unplugged = 1    //设备不是插入电源,电池放电case charging = 2    //设备插入电源和电池充电不到100%case full = 3        //设备插入电源和电池充电100%
}

电池电量监测

//开启电量监测
UIDevice.current.isBatteryMonitoringEnabled = true
//注册电量监测事件
NotificationCenter.default.addObserver(self, selector: #selector(batteryDidChange), name: UIDevice.batteryLevelDidChangeNotification, object: nil)
@objc func batteryDidChange() {print("batteryLevel", UIDevice.current.batteryLevel)
}

http://www.lryc.cn/news/161979.html

相关文章:

  • SLAM ORB-SLAM2(2)编译安装
  • 第11节-PhotoShop基础课程-索套工具
  • Json字符串内容比较-超实用版
  • Redis系列之客户端Redisson
  • centos 端口被占用的快速排查方式
  • Java“牵手”淘宝商品列表数据,关键词搜索淘宝商品数据接口,淘宝API申请指南
  • OpenEuler/CentOS如何修改密码策略
  • # Spring MVC与RESTful API:如何设计高效的Web接口
  • Scrum敏捷模式的优势点、实践经验及适用企业
  • 【C++杂货铺】探索stack和queue的底层实现
  • “系统的UI”——SystemUI
  • 类和对象:构造函数,析构函数与拷贝构造函数
  • 谈谈Java的特点和优点以及选择Java的原因
  • 消息队列(MQ)面试
  • 无涯教程-JavaScript - COUPNUM函数
  • 上海控安携汽车网络安全新研产品出席AUTOSEMO“恒以致远,共创共赢”主题研讨会
  • 小程序引入高德/百度地图坐标系详解
  • 英诺森 “供应链智能数据平台”荣获“科技进步奖”
  • kafka 3.5 主题分区的Follower创建Fetcher线程从Leader拉取数据源码
  • Golang web 项目中实现自定义 recovery 中间件
  • Direct3D绘制旋转立方体例程
  • ElementUI浅尝辄止31:Tabs 标签页
  • 将 ChatGPT 用于数据科学项目的指南
  • 06-JVM对象内存回收机制深度剖析
  • [VSCode] 替换掉/去掉空行
  • 时序分解 | MATLAB实现ICEEMDAN+SE改进的自适应经验模态分解+样本熵重构分量
  • python内网环境安装第三方包【内网搭建开发环境】
  • 7.13 在SpringBoot中 正确使用Validation实现参数效验
  • Matlab图像处理之Lee滤波器
  • C++系列-const修饰的常函数