【问题标题】:How to detect if it's running on iPhone or iPad?如何检测它是否在 iPhone 或 iPad 上运行?
【发布时间】:2014-11-18 19:10:33
【问题描述】:

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

【问题讨论】:

  • 首先,当您启动应用程序时,您必须选择仅适用于 iPhone 而不是通用
  • 是的,我选择 iPhone,但如何知道它是在 iPhone 还是 iPad 上运行?

标签: ios objective-c device


【解决方案1】:

我会退后一步,询问您需要这些信息的目的。

每个 iPhone 应用程序都可以在 iPad 或 iPod Touch 上运行。如果你假设你的应用可以打电话,那么这个假设显然是错误的。处理器可能出乎意料地快。但原则上,您的应用程序应该保持不变运行,Apple 在 iPad 上运行它的事实对您没有任何影响。有数十万个 iPhone 应用程序都可以在 iPad 上毫无问题地运行,并且无需任何开发人员的工作。

您的应用显然不会被告知用户界面是 UIUserInterfaceIdiomPad,因为您有一个 iPhone 应用,即使在 iPad 上它也应该显示 iPhone UI。

【讨论】:

  • 我会告诉你为什么。原因是 iPhone 横幅广告和 iPad 横幅广告的大小和位置不同。如果苹果在 iPad 上测试 iPhone 应用,横幅广告会出现在屏幕中间,阻碍用户使用应用,从而导致应用被拒绝。这就是为什么应用需要知道它是在 iPhone 还是 iPad 上运行的原因。
【解决方案2】:

试试这个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

}

【讨论】:

    【解决方案3】:

    你可以从

    获取信息
    [[UIDevice currentDevice] model]
    

    UIDevice

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      相关资源
      最近更新 更多