如何检查设备是否 iPad 或 iPhone 不工作
How to check if device is an iPad or iPhone not working
我目前正在更新一个应用程序,我需要知道该应用程序是否正在 iPad 中使用。
我在网上查了一下,找到了下面的代码。我在 Xcode 和 运行 两个 if 语句中都使用了 iPad 模拟器。但是每当我 运行 代码时,什么都没有发生(打印消息不打印)这段代码是否适用于模拟器或者我做错了什么?
当我检查它是否是 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")
}
但您需要让您的应用成为通用应用。
如果要经常查看iphone/ipad。使用以下 class
class Env {
static var isIpad : Bool { return UIDevice.current.userInterfaceIdiom == .pad }
}
然后你可以这样使用
if Env.isIpad { // Ipad }
else { iphone }
您可以使用:
如果UIDevice.current.model == "iPad" {
}
我目前正在更新一个应用程序,我需要知道该应用程序是否正在 iPad 中使用。
我在网上查了一下,找到了下面的代码。我在 Xcode 和 运行 两个 if 语句中都使用了 iPad 模拟器。但是每当我 运行 代码时,什么都没有发生(打印消息不打印)这段代码是否适用于模拟器或者我做错了什么?
当我检查它是否是 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")
}
但您需要让您的应用成为通用应用。
如果要经常查看iphone/ipad。使用以下 class
class Env {
static var isIpad : Bool { return UIDevice.current.userInterfaceIdiom == .pad }
}
然后你可以这样使用
if Env.isIpad { // Ipad }
else { iphone }
您可以使用:
如果UIDevice.current.model == "iPad" {
}