gpt4 book ai didi

iphone - 检测最新的苹果设备 Xs、X(R)

转载 作者:行者123 更新时间:2023-12-03 20:39:36 24 4
gpt4 key购买 nike

我需要以编程方式检测最新的 iPhone 设备。我有以前型号的所有设备标识符,但我需要 iPhone Xs max、iPhone Xs、iPhone X(R) 的设备标识符。

最佳答案

适用于XCode 9Swift 4

extension UIDevice {
var iPhoneX: Bool {
return UIScreen.main.nativeBounds.height == 2436
}
var iPhone: Bool {
return UIDevice.current.userInterfaceIdiom == .phone
}
enum ScreenType: String {
case iPhones_4_4S = "iPhone 4 or iPhone 4S"
case iPhones_5_5s_5c_SE = "iPhone 5, iPhone 5s, iPhone 5c or iPhone SE"
case iPhones_6_6s_7_8 = "iPhone 6, iPhone 6S, iPhone 7 or iPhone 8"
case iPhones_6Plus_6sPlus_7Plus_8Plus = "iPhone 6 Plus, iPhone 6S Plus, iPhone 7 Plus or iPhone 8 Plus"
case iPhones_X_XS = "iPhone X or iPhone XS"
case iPhone_XR = "iPhone XR"
case iPhone_XSMax = "iPhone XS Max"
case unknown
}
var screenType: ScreenType {
switch UIScreen.main.nativeBounds.height {
case 960:
return .iPhones_4_4S
case 1136:
return .iPhones_5_5s_5c_SE
case 1334:
return .iPhones_6_6s_7_8
case 1792:
return .iPhone_XR
case 1920, 2208:
return .iPhones_6Plus_6sPlus_7Plus_8Plus
case 2436:
return .iPhones_X_XS
case 2688:
return .iPhone_XSMax
default:
return .unknown
}
}
}

简单地使用这个:

print("screen Type:", UIDevice.current.screenType.rawValue)

也可以访问此了解 iPhone 设备的屏幕分辨率。

https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

关于iphone - 检测最新的苹果设备 Xs、X(R),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52366745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com