查看手機名稱,iOS 版本,型號等資訊:
亦可查看手機目前電池使用狀況:
而電池的使用狀態由此得知:
目前系統提供下列電池的狀態:
App 建立步驟:
1. 新增 Single View App
//
// ViewController.swift
// DeviceStatus
//
// Created by Elvis Meng on 2015/9/16.
// Copyright (c) 2015年 Elvis Meng. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
UIDevice.currentDevice().batteryMonitoringEnabled = true
println("Model Name: \(UIDevice.currentDevice().model)")
println("Batery Open? \(UIDevice.currentDevice().batteryMonitoringEnabled)")
println("Battery Level: \(UIDevice.currentDevice().batteryLevel)")
println("Battery State: \(UIDevice.currentDevice().batteryState.hashValue)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
測試:
後記:
注意到沒?為何 iDevice 註冊後,設定 .batteryMonitoringEnabled = true,但 Batery Open? 的值仍為 false。這是 Bug? 我懷疑也相信。
參考:
1. UIDevice, https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIDevice_Class/
2. iOS SDK详解之UIDevice(系统版本,设备型号...), http://blog.csdn.net/Hello_Hwc/article/details/46326571
prettyprint
2015年9月21日 星期一
查看手機目前使用狀態
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言