gpt4 book ai didi

ios - 如何使用swift检查iphone型号

转载 作者:IT王子 更新时间:2023-10-29 05:38:43 26 4
gpt4 key购买 nike

我们如何在 Swift 中检查 iPhone 型号(例如 iPhone 4/iPhone5)。使用下面的代码我可以检查它是否是 iPod 的 iPhone。

let iphoneModel = UIDevice.currentDevice().model
if (iphoneModel == "iPhone"){
println("Iphone 4")
}

我需要具体知道它是哪种 iPhone 型号。

最佳答案

使用以下代码。 (Reference from)

enum UIUserInterfaceIdiom : Int
{
case Unspecified
case Phone
case Pad
}

struct ScreenSize
{
static let SCREEN_WIDTH = UIScreen.mainScreen().bounds.size.width
static let SCREEN_HEIGHT = UIScreen.mainScreen().bounds.size.height
static let SCREEN_MAX_LENGTH = max(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
static let SCREEN_MIN_LENGTH = min(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
}

struct DeviceType
{
static let IS_IPHONE_4_OR_LESS = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH < 568.0
static let IS_IPHONE_5 = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0
static let IS_IPHONE_6 = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 667.0
static let IS_IPHONE_6P = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 736.0
static let IS_IPAD = UIDevice.currentDevice().userInterfaceIdiom == .Pad && ScreenSize.SCREEN_MAX_LENGTH == 1024.0
}

并将其用作:

if DeviceType.IS_IPHONE_6P {
println("IS_IPHONE_6P")
}

关于ios - 如何使用swift检查iphone型号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26117579/

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