gpt4 book ai didi

ios - iPad Retina 模型快速识别

转载 作者:行者123 更新时间:2023-11-29 00:59:13 26 4
gpt4 key购买 nike

我试图识别 iPad Retina 是否有我的应用程序,然后更改我的代码中的某些内容。到目前为止,我从互联网上找到了这张模型图,而且我还从 iPad Pro 上找到了这张模型图。

public enum Model : String {
case simulator = "simulator/sandbox",
iPod1 = "iPod 1",
iPod2 = "iPod 2",
iPod3 = "iPod 3",
iPod4 = "iPod 4",
iPod5 = "iPod 5",
iPad2 = "iPad 2",
iPad3 = "iPad 3",
iPad4 = "iPad 4",
iPhone4 = "iPhone 4",
iPhone4S = "iPhone 4S",
iPhone5 = "iPhone 5",
iPhone5S = "iPhone 5S",
iPhone5C = "iPhone 5C",
iPadMini1 = "iPad Mini 1",
iPadMini2 = "iPad Mini 2",
iPadMini3 = "iPad Mini 3",
iPadAir1 = "iPad Air 1",
iPadAir2 = "iPad Air 2",
iPhone6 = "iPhone 6",
iPhone6plus = "iPhone 6 Plus",
iPhone6S = "iPhone 6S",
iPhone6Splus = "iPhone 6S Plus",
iPadPro = "iPad Pro",
iPadRetina = "iPad Retina",
unrecognized = "?unrecognized?"
}

public extension UIDevice {
public var type: Model {
var systemInfo = utsname()
uname(&systemInfo)
let modelCode = withUnsafeMutablePointer(&systemInfo.machine) {
ptr in String.fromCString(UnsafePointer<CChar>(ptr))
}
var modelMap : [ String : Model ] = [
"i386" : .simulator,
"x86_64" : .simulator,
"iPod1,1" : .iPod1,
"iPod2,1" : .iPod2,
"iPod3,1" : .iPod3,
"iPod4,1" : .iPod4,
"iPod5,1" : .iPod5,
"iPad2,1" : .iPad2,
"iPad2,2" : .iPad2,
"iPad2,3" : .iPad2,
"iPad2,4" : .iPad2,
"iPad2,5" : .iPadMini1,
"iPad2,6" : .iPadMini1,
"iPad2,7" : .iPadMini1,
"iPhone3,1" : .iPhone4,
"iPhone3,2" : .iPhone4,
"iPhone3,3" : .iPhone4,
"iPhone4,1" : .iPhone4S,
"iPhone5,1" : .iPhone5,
"iPhone5,2" : .iPhone5,
"iPhone5,3" : .iPhone5C,
"iPhone5,4" : .iPhone5C,
"iPad3,1" : .iPad3,
"iPad3,2" : .iPad3,
"iPad3,3" : .iPad3,
"iPad3,4" : .iPad4,
"iPad3,5" : .iPad4,
"iPad3,6" : .iPad4,
"iPhone6,1" : .iPhone5S,
"iPhone6,2" : .iPhone5S,
"iPad4,1" : .iPadAir1,
"iPad4,2" : .iPadAir2,
"iPad4,4" : .iPadMini2,
"iPad4,5" : .iPadMini2,
"iPad4,6" : .iPadMini2,
"iPad4,7" : .iPadMini3,
"iPad4,8" : .iPadMini3,
"iPad4,9" : .iPadMini3,
"iPhone7,1" : .iPhone6plus,
"iPhone7,2" : .iPhone6,
"iPhone8,1" : .iPhone6S,
"iPhone8,2" : .iPhone6Splus,
"iPad6,3" : .iPadPro,
"iPad6,4" : .iPadPro,
"iPad6,7" : .iPadPro,
"iPad6,8" : .iPadPro
]

if let model = modelMap[String.fromCString(modelCode!)!] {
return model
}
return Model.unrecognized
}
}

我用这个简单的大小写切换代码检查了用户拥有的模型

 switch UIDevice().type {
case .iPhone4S:
print("iphone4s")
case .iPhone5:
print("iphone5")
case .iPadAir2:
print("mos def im an ipad air 2")
case .iPadPro:
print("am i an ipad Pro?")
default:
print("i'm a pretty little simulator")
}

所以我的问题是这些首先,因为我没有ipad Pro,所以代码正确吗?最后,我应该怎么做才能识别 ipad Retina ???

非常感谢!

最佳答案

不要自己编写这些条件。使用此 pod 确定您的应用程序在哪个设备上运行,如果 apple 发布另一种设备类型,只需执行 pod 更新,其余的将由您自己完成。 https://github.com/dennisweissmann/DeviceKit

关于ios - iPad Retina 模型快速识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37215952/

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