ios - 如何检查设备是 iPad 还是 iPhone 不工作

标签 ios swift uikit ios-simulator

我目前正在更新一个应用程序,我需要知道该应用程序是否正在 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/

相关文章:

ios - SFSafariViewController 完成按钮不起作用/触摸区域太小

javascript - youtube javascript API 检测 iOS 设备上的全屏退出

iOS 媒体播放控制通知

objective-c - EKCalendarChooser 多项选择不起作用

ios - 如何更改 UISearchBar 占位符和图像色调颜色?

ios - 是否可以自动化涉及 iOS 应用程序双因素身份验证的测试?

iphone - 如何更改 uinavigationbar 后退按钮文本

快速使用谓词

ios - 访问由私有(private) managedObjectContext 创建的 CoreData 对象(在后台线程中创建)

swift - 为 presentedViewController 设置委托(delegate)(例如不使用 segues)