iOS SDK详解之UIDevice(系统版本,设备型号...)
2015-06-02 11:47
537 查看
原创Blog,转载请注明出处
blog.csdn.net/hello_hwc
欢迎关注我的iOS SDK详解专栏
blog.csdn.net/column/details/huangwenchen-ios-sdk.html
前言:UIDevice是初学者很容易忽视的一个类。通过这个类的API可以很容易的获取到当前的设备信息,系统信息。没什么难度,本文会详细的阐述各个属性。
本文的输出值都是在我的iPhone 5s下的值
设备
设备名称
返回类型
系统版本
返回类型
设备型号
返回类型
ipad/Iphone
返回类型
有三种
厂商
返回类型
返回float,0到1之间,1代表100%电量
电量的状态-
返回UIDeviceBatteryState
是否监听电量-batteryMonitoringEnabled
如果设为YES,则可以监听电量的变化和获取电量的状态。默认为NO
有两个notification可以订阅
UIDeviceBatteryStateDidChangeNotification
UIDeviceOrientationDidChangeNotification
获取设备的物理方向-orientation
返回类型
是否发送通知-generatesDeviceOrientationNotifications
如果是YES,那么设备方向改变了,会post这个通知UIDeviceOrientationDidChangeNotification 。当然这个通知也是可以订阅的。
注意,获取方向的时候要在这两个函数之间获取
需要在自定义的输入view下这么做
让自定义输入视图遵循
实现方法
blog.csdn.net/hello_hwc
欢迎关注我的iOS SDK详解专栏
blog.csdn.net/column/details/huangwenchen-ios-sdk.html
前言:UIDevice是初学者很容易忽视的一个类。通过这个类的API可以很容易的获取到当前的设备信息,系统信息。没什么难度,本文会详细的阐述各个属性。
本文的输出值都是在我的iPhone 5s下的值
设备
设备名称
返回类型
String
let deviceName = UIDevice.currentDevice().name //***的iPhone
系统版本
返回类型
String
let systemName = UIDevice.currentDevice().systemName//iPhone OS let systemVersion = currentDevice.systemVersion// 8.3
设备型号
返回类型
String
let deviceModel = UIDevice.currentDevice().model// iPhone let localModel = UIDevice.currentDevice().localizedModel// iPhone
ipad/Iphone
返回类型
UIUserInterfaceIdiom
有三种
enum UIUserInterfaceIdiom : Int { case Unspecified case Phone //iPhone 和 iTouch case Pad //Ipad }
let deviceType = UIDevice.currentDevice().userInterfaceIdiom//Phone
厂商
返回类型
NSUUID!
let vender = UIDevice.currentDevice().identifierForVendor
电池
剩余电量 -batteryLevel
返回float,0到1之间,1代表100%电量
电量的状态-
batteryState
返回UIDeviceBatteryState
enum UIDeviceBatteryState : Int { case Unknown //未知 case Unplugged//没有在充电 case Charging//在充电 case Full//满电 }
是否监听电量-batteryMonitoringEnabled
如果设为YES,则可以监听电量的变化和获取电量的状态。默认为NO
UIDevice.currentDevice().batteryMonitoringEnabled = true let batteryLevel = UIDevice.currentDevice().batteryLevel//0.550000012 let batteryState = UIDevice.currentDevice().batteryState//Charging
有两个notification可以订阅
UIDeviceBatteryStateDidChangeNotification
UIDeviceOrientationDidChangeNotification
设备旋转
注意,这里的是设备的物理方向,不是屏幕的方向获取设备的物理方向-orientation
返回类型
enum UIDeviceOrientation : Int { case Unknown case Portrait case PortraitUpsideDown case LandscapeLeft case LandscapeRight case FaceUp case FaceDown }
是否发送通知-generatesDeviceOrientationNotifications
如果是YES,那么设备方向改变了,会post这个通知UIDeviceOrientationDidChangeNotification 。当然这个通知也是可以订阅的。
注意,获取方向的时候要在这两个函数之间获取
UIDevice.currentDevice().beginGeneratingDeviceOrientationNotifications() let orientation = UIDevice.currentDevice().orientation//Portrait UIDevice.currentDevice().endGeneratingDeviceOrientationNotifications()
设备是否接近脸
proximityMonitoringEnabled proximityState
是否支持多任务
multitaskingSupported
播放输入的声音
playInputClick()
需要在自定义的输入view下这么做
让自定义输入视图遵循
UIInputViewAudioFeedback protocol
实现方法
enableInputClicksWhenVisible并且返回true
相关文章推荐
- 手机APP UI设计尺寸基础知识
- CSRF(Cross-site request forgery)跨站请求伪造
- firefox30浏览器,在使用quit()方法退出时,plugin-container.exe崩溃的问题
- 长时间停留在calculating requirements and dependencies 的解决方案
- web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 86-100
- MYSQL Optimizing LIMIT Queries
- IOS开发----UIImagePickerController详细用法
- GRE Issue 范文 Topic 5
- UIKit 框架之UICollectionViewController
- dyld: Symbol not found: _OBJC_CLASS_$_UIBlurEffect
- ArrayBlockingQueue和ExecutorService的理解与感悟
- iOS学习(1)——UIButton
- 优化UITableViewCell高度计算的那些事
- 后台request获得所有参数(当你不知道它包含什么参数)
- UIImage 按照指定宽度等比例裁切
- GRE ISSUE写作论证论据素材 国家制度建设类
- UIKit 框架之UISearchController
- APUE: Ext2文件系统布局,文件数据块寻址,VFS虚拟文件系统
- poj2478 Farey Sequence(线性筛法+欧拉函数+递推)
- Arch下Android Studio下报错Cannot run program "/xx/build-tools/xx/aapt": error=2解决