打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
iOS SDK详解之UIDevice(系统版本,设备型号...)

原创Blog,转载请注明出处
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
  • 1
  • 2
  • 1
  • 2

系统版本
返回类型String

 let systemName = UIDevice.currentDevice().systemName//iPhone OS let systemVersion = currentDevice.systemVersion// 8.3
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

设备型号
返回类型String

let deviceModel = UIDevice.currentDevice().model// iPhonelet localModel = UIDevice.currentDevice().localizedModel// iPhone
  • 1
  • 2
  • 1
  • 2

ipad/Iphone
返回类型UIUserInterfaceIdiom
有三种

enum UIUserInterfaceIdiom : Int {    case Unspecified     case Phone //iPhone 和 iTouch    case Pad //Ipad}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5
let deviceType = UIDevice.currentDevice().userInterfaceIdiom//Phone
  • 1
  • 1

厂商
返回类型NSUUID!

 let vender = UIDevice.currentDevice().identifierForVendor
  • 1
  • 1

电池

剩余电量 -batteryLevel
返回float,0到1之间,1代表100%电量

电量的状态-batteryState
返回UIDeviceBatteryState

enum UIDeviceBatteryState : Int {    case Unknown //未知    case Unplugged//没有在充电    case Charging//在充电    case Full//满电}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

是否监听电量-batteryMonitoringEnabled
如果设为YES,则可以监听电量的变化和获取电量的状态。默认为NO

 UIDevice.currentDevice().batteryMonitoringEnabled = true let batteryLevel = UIDevice.currentDevice().batteryLevel//0.550000012 let batteryState = UIDevice.currentDevice().batteryState//Charging
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

有两个notification可以订阅

  • UIDeviceBatteryStateDidChangeNotification
  • UIDeviceOrientationDidChangeNotification

设备旋转

注意,这里的是设备的物理方向,不是屏幕的方向
获取设备的物理方向-orientation
返回类型

enum UIDeviceOrientation : Int {    case Unknown    case Portrait    case PortraitUpsideDown    case LandscapeLeft    case LandscapeRight    case FaceUp    case FaceDown}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

是否发送通知-generatesDeviceOrientationNotifications
如果是YES,那么设备方向改变了,会post这个通知UIDeviceOrientationDidChangeNotification 。当然这个通知也是可以订阅的。

注意,获取方向的时候要在这两个函数之间获取

 UIDevice.currentDevice().beginGeneratingDeviceOrientationNotifications()        let orientation = UIDevice.currentDevice().orientation//Portrait       UIDevice.currentDevice().endGeneratingDeviceOrientationNotifications()
  • 1
  • 2
  • 1
  • 2

设备是否接近脸

proximityMonitoringEnabledproximityState
  • 1
  • 2
  • 1
  • 2

是否支持多任务

multitaskingSupported
  • 1
  • 1

播放输入的声音

  playInputClick()
  • 1
  • 1

需要在自定义的输入view下这么做

  • 让自定义输入视图遵循UIInputViewAudioFeedback protocol
  • 实现方法enableInputClicksWhenVisible 并且返回true

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
iOS获取设备型号和App版本号等信息
如何获取iPhone电池的状态和当前的电量
Swift开发之 获取手机设备信息
IOS适配屏幕
iOS8 强制选择
解决iOS项目的版本兼容问题
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服