swift get ios device type
Better Code: Determine Device Types and iOS Versions – TechRepublic
Determine iPhone and iPad Hardware Machine and Device Type iOS(developer: tips)
iOS device checks for OS version and screen size in Swift
ios – How to get the device type in Swift TodayExtension – Stack Overflow
osx – How to determine device type from Swift? (OS X or iOS) – Stack Overflow
ios – Detect current device with UI_USER_INTERFACE_IDIOM() in Swift – Stack Overflow
iOS: How to determine iphone model in Swift? – Stack Overflow
【总结】
let deviceModel = UIDevice.currentDevice().model print("deviceModel=\(deviceModel)") let localizedModel = UIDevice.currentDevice().localizedModel print("localizedModel=\(localizedModel)") let deviceName = UIDevice.currentDevice().name print("deviceName=\(deviceName)") let iOSVersion = UIDevice.currentDevice().systemVersion print("iOSVersion=\(iOSVersion)") let deviceDesc = UIDevice.currentDevice().description print("deviceDesc=\(deviceDesc)") let systemName = UIDevice.currentDevice().systemName print("systemName=\(systemName)") |
对于iOS 模拟器:iPhone 5,的输出是:
deviceModel=iPhone localizedModel=iPhone deviceName=iPhone Simulator iOSVersion=9.3 deviceDesc=<UIDevice: 0x7883e340> systemName=iPhone OS |
对于真机iPhone 6的输出是:
deviceModel=iPhone localizedModel=iPhone deviceName=Crifan iPhone6 iOSVersion=9.3 deviceDesc=<UIDevice: 0x144d14fc0> systemName=iPhone OS |
目前用如下代码:
/*************************************************************************** * Device functions ***************************************************************************/ public enum DeviceModel: String { //public extension UIDevice { "iPod1,1" : .iPod1, "iPad2,1" : .iPad2, return DeviceModel.Unknown public var isPod:Bool { } var phoneType = UIDevice.currentDevice().curDeviceType.rawValue print("phoneType=\(phoneType)") //phoneType=iPhone 6 phoneType = phoneType.replace(" ", to: "") print("phoneType=\(phoneType)") //iPhone6 phoneType = phoneType.lowercaseString print("phoneType=\(phoneType)") //iphone6 var iOSVersion = UIDevice.currentDevice().systemVersion //9.3 |
转载请注明:在路上 » [已解决]swift获取iOS设备类型和iOS版本