【问题标题】:How do I distinguish iPad 1 from iPad 2 in Cocoa?如何在 Cocoa 中区分 iPad 1 和 iPad 2?
【发布时间】:2011-05-13 12:27:42
【问题描述】:

我的应用需要知道 iPad 的麦克风在哪里,而我知道的唯一方法是查看它是在 iPad 上还是在 iPad 2 上运行,然后采取相应措施。

那么 - 我如何检查设备型号?

【问题讨论】:

  • 很抱歉我不能直接回答你的问题,但一般来说,如果你想测试麦克风的存在,那就测试麦克风的存在。间接性不好(你可能不在乎,但如果你检查它是 iPad 2,当 iPad 3 出来时会发生什么?)。这是不好的做法......
  • 虽然这并不能告诉你答案,但请阅读这里 -> blog.mugunthkumar.com/coding/…
  • @Dave - 谢谢,但我不想测试麦克风的存在(iPad1 也有麦克风),我需要测试麦克风的 location - iPad1 在耳机端口附近有一个麦克风,iPad2 在中间有一个麦克风。
  • 啊,我明白了!我的错 - 很高兴我能在下面提供帮助!

标签: cocoa-touch ipad


【解决方案1】:

要做到这一点,您需要:

if(![[UIDevice currentDevice].model isEqualToString:@"iPad2"])
{
UIAlertView *alertView = [UIAlertView alloc] initWithTitle:@"Error" 
message:@"Microphone not present" 
delegate:self 
cancelButtonTitle:@"Dismiss" 
otherButtonTitles: nil];
[alertView show];
[alertView release];
}

取自here

但正如我上面所说,测试麦克风的存在要比测试确切的型号更好。如果有人使用带有外接麦克风的 iPad 1 怎么办?

编辑:This is the correct method,抱歉,梅林。

还报道了in this stackoverflow question.

戴夫

【讨论】:

  • 谢谢 :) 正如我在评论中提到的 - 我需要 位置,而不是麦克风的可用性。我知道这不是一个好习惯,但我认为没有 Api 可以告诉我麦克风的位置:)
  • 很高兴听到 - 很抱歉误解了这个问题!
  • 欧。我刚刚在真实设备上测试了代码 - iPad2 返回@"iPad",而不是@"iPad2" 作为设备型号:(
  • 梅林 - 道歉......这是正确的方法 - arstechnica.com/apple/guides/2009/03/…
  • 是的,尤其是初始方法不起作用,因为 iPad 1 也有麦克风。
【解决方案2】:

此 SO 答案提供了使用 sysctlbyname("hw.machine"... 系统的详细方法。

Determine device (iPhone, iPod Touch) with iPhone SDK

【讨论】:

    猜你喜欢
    • 2012-01-16
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    • 2012-07-22
    相关资源
    最近更新 更多