gpt4 book ai didi

ios - userInterfaceIdiom 在真实设备上返回错误值

转载 作者:行者123 更新时间:2023-11-30 13:45:02 25 4
gpt4 key购买 nike

我的应用程序被拒绝,因为我的应用程序的 iPad UI 存在问题。在被拒绝之前,我已经修复了这个问题,方法是检查设备是否是 iPad,并对 UI 措施进行一些细微的调整。问题是当我打电话时:

UIDevice.currentDevice().userInterfaceIdiom //returns .Unspecified
traitCollection.userInterfaceIdiom //returns -1

在真正的 iPad 上,我得到了 .Unspecified。这是为什么?

最佳答案

为了解决这个问题,我创建了一个自定义方法,它实际上可以在真正的 iPad 上运行

public extension UIDevice {

func isIpadDevice() -> Bool {
let identifier = deviceIdentifier()

return identifier.lowercaseString.containsString("ipad")
}

private func deviceIdentifier() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8 where value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}

return identifier
}

}

为了使用它,请调用

UIDevice.currentDevice().isIpadDevice() //wohoo

关于ios - userInterfaceIdiom 在真实设备上返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35063316/

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