ios - 如何检测它是在 iPhone 还是 iPad 上运行?

标签 ios objective-c device

我有一个在 iPhone 上运行的应用程序,但是当我提交给 Apple 审查时,他们正在 iPad 上测试它。我如何检测它是否在 iPad 上运行 iPhone 应用程序?我尝试使用 UIUserInterfaceIdiomPad 但显然它只适用于通用应用程序而不适用于 iPhone 应用程序。

最佳答案

试试这个 UIDevice 类方法

 [[UIDevice currentDevice] name]              // like "S R Nayak's iPhone"
 [[UIDevice currentDevice] model]             // like @"iPhone", @"iPod Touch"
 [[UIDevice currentDevice] localizedModel]    // localized version of model
 [[UIDevice currentDevice] systemName]        // like @"iPhone OS"
 [[UIDevice currentDevice] systemVersion]     // like @"4.0"
 [[UIDevice currentDevice] uniqueIdentifier]  // UDID, a unique string to identify the device

否则你可以检查:

 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
[[[UIDevice currentDevice] model] hasPrefix:@"iPad"]) {
// This app is an iPhone app but running on an iPad

关于ios - 如何检测它是在 iPhone 还是 iPad 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26014397/

相关文章:

objective-c - 如何在 Objective-C 中将 heic 转换为 jpg

ios - 沿贝塞尔路径放置图像

android - 通过 ADB 创建 AVD 配置文件

error-handling - xCode 6.1| stdlib-tool 因退出代码而失败

android - 要嵌入 iOS/Android-View 的跨平台 3d 引擎?

ios - 动画和隐藏横幅 Admob

ios - NSDecimalNumber的数学完整性

ios - 分页在 collectionview 中是如何工作的?

objective-c - 在哪里声明枚举结构?

android - 在哪里运行 adb Kill-server 命令以解决 Intellij IDEA Android "USB Device not found"错误