我目前正在更新一个应用程序,我需要知道该应用程序是否正在 iPad 上使用。
我在网上查了一下,找到了下面的代码。我在 Xcode 中使用了 iPad 模拟器并运行了两个 if 语句。但是每当我运行代码时,什么都没有发生(打印消息不打印)这段代码是否适用于模拟器,还是我做错了什么?
当我检查它是否是 UIUserInterfaceIdiom.phone 时,打印语句会执行,但我在模拟器中使用的是 iPad。
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad){
print("This is an iPad")
redoButton.layer.position.y -= 500
}
if UIDevice.current.userInterfaceIdiom == .pad{
print("iPad True")
}
谢谢
最佳答案
if UIDevice.current.userInterfaceIdiom == .pad {
print("iPad")
}else{
print("not iPad")
}
但您需要让您的应用成为通用应用。
关于ios - 如何检查设备是 iPad 还是 iPhone 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49724902/