代码之家  ›  专栏  ›  技术社区  ›  Aftermathew

如何判断您的代码是在iPhone上运行还是在iPhone 3G上运行?

  •  22
  • Aftermathew  · 技术社区  · 17 年前

    我试图确定我的代码是在iPhone上运行还是在iPhone 3G上运行。我的第一次尝试是在UIKit中使用UIDevice类,但iPhone和iPhone3G都返回相同的响应:

    NSLog([[UIDevice currentDevice] name]); // Name of the phone as named by user
    NSLog([[UIDevice currentDevice] uniqueIdentifier]); // A GUID like string
    NSLog([[UIDevice currentDevice] systemName]); // "iPhone OS" 
    NSLog([[UIDevice currentDevice] systemVersion]); // "2.2.1"
    NSLog([[UIDevice currentDevice] model]); // "iPhone" on both devices
    NSLog([[UIDevice currentDevice] localizedModel]); // "iPhone" on both devices
    

    我看了一下基础框架,但还没有找到合适的调用。

    我肯定有一些硬件我可以查询(比如定位服务中的一些东西),但这看起来像是黑客攻击。有人知道一个简单的方法来确定这一点吗?

    3 回复  |  直到 9 年前
        1
  •  21
  •   ephemient    17 年前

    iPhone运行OSX。 Here's Here's 如何在iPhone上使用。完全一样。

    简言之 sysctlbyname("hw.machine", str, sz, 0, 0) str . 这恰好是iPhone和iPhone3G的“iPhone1,1”或“iPhone1,2”。

        2
  •  6
  •   Steve Rowe    17 年前

    我不是iPhone开发者,但检查底层平台而不是平台功能几乎总是错误的选择。如果iPhone获得了您需要的功能,您仍然无法运行。你也有可能在下一代iPhone4.0(或其他任何名称)上做出错误的决定。

        3
  •  0
  •   Mike Buckbee    15 年前