UIDevice サンプル
サンプルで動作を確認 コピーペーストで確認できます。
// ディバイスの OS 名称を取得します。例:iPhone OS
print(UIDevice.currentDevice().systemName)
// OS のバージョンを取得。例:9.1
print(UIDevice.currentDevice().systemVersion)
// 端末の名称を取得します。例:iPhone Simulator
print(UIDevice.currentDevice().name)
// 端末のモデルを取得します。例:iPhone
print(UIDevice.currentDevice().model)
// 端末のローカルのモデルを取得します。例:iPhone
print(UIDevice.currentDevice().localizedModel)
// iPhone iPad の判別を取得します。例:iPhone または iPad
print(UIDevice.currentDevice().userInterfaceIdiom)
// アプリ開発元でユニークな、IDを取得します。
print(UIDevice.currentDevice().identifierForVendor)
// 表示されている画面の向きを取得します。例:UIDeviceOrientation
print(UIDevice.currentDevice().orientation)
// マルチタスクをサポートしているかを取得します。例:true
print(UIDevice.currentDevice().multitaskingSupported)
// アプリ内でバッテリーの状態を取得、管理したい場合の設定をします。
UIDevice.currentDevice().batteryMonitoringEnabled = true
// バッテリーの有無の状態を取得します。0.0~1.0 例:0.4
print(UIDevice.currentDevice().batteryLevel)
// バッテリーの状態を取得します。例:UIDeviceBatteryState
print(UIDevice.currentDevice().batteryState)
// 接近センサーの有効、無効を設定します。(電話中に顔等が接近状態)
UIDevice.currentDevice().proximityMonitoringEnabled = true
// 接近センサーの状態を取得します。例:false
print(UIDevice.currentDevice().proximityState)
UIDevice 概要
UIDevice 関連の情報を取得します。
- Import Statement
import UIKit - Available
iOS 2.0 and later - Inherits
NSObject
画面の向き
■ UIDevice.currentDevice().orientation
画面の向き一覧
// 縦
UIDeviceOrientationPortrait
// 縦、上下逆
UIDeviceOrientationPortraitUpsideDown
// 左向き横
UIDeviceOrientationLandscapeLeft
// 右向き横
UIDeviceOrientationLandscapeRight
// 本体を置いた状態で画面が上向き
UIDeviceOrientationFaceUp
// 本体を置いた状態で画面が下向き
UIDeviceOrientationFaceDown
// 不明
UIDeviceOrientationUnknown
バッテリー状態
■ UIDevice.currentDevice().batteryState
バッテリー状態一覧
// ケーブル未接続
UIDeviceBatteryStateUnplugged
// 充電中
UIDeviceBatteryStateCharging
// フル状態
UIDeviceBatteryStateFull
// 不明
UIDeviceBatteryStateUnknown
おすすめの本