iPhone 检测处理器型号/NEON 支持

发布于 2024-08-09 06:49:11 字数 352 浏览 3 评论 0原文

我正在寻找一种方法来在运行时区分配备新 ARM 处理器的设备(例如 iPhone 3GS 和一些 iPod 3G)和配备旧 ARM 处理器的设备。 我知道我可以使用 uname() 来确定设备型号,但由于只有部分 iPod touch 3G 的 ARM 处理器得到了增强,这还不够。

因此,我正在寻找其中之一:

  1. 一种检测处理器模型的方法 - 我想没有。
  2. 一种确定是否支持 ARM neon 指令的方法 - 由此我可以得出答案。
  3. 一种确定设备总存储大小的方法 - 将其与已知的设备模型相结合可以巧妙地引导我找到答案。
  4. <输入随机想法>

提前致谢 :)

I'm looking for a way to differentiate at runtime between devices equipped with the new ARM processor (such as iPhone 3GS and some iPods 3G) and devices equipped with the old ARM processors.
I know I can use uname() to determine the device model, but as only some of the iPod touches 3G received a boost in their ARM processor, this isn't enough.

Therefore, I'm looking for one of these:

  1. A way of detecting processor model - I suppose there's none.
  2. A way of determining whether ARM neon instructions are supported - from this I could derive an answer.
  3. A way of determining the devices total storage size - combining this with the already known device model could hackishly lead me to the answer.
  4. < ENTER RANDOM IDEA >

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

末骤雨初歇 2024-08-16 06:49:11

不完全是您所要求的,但一种简单的解决方案是构建胖应用程序,以便它包含 ARMv6 和 ARMv7 的可执行代码。如果这样做,适当的代码将自动在处理器上运行,并且您不需要进行任何运行时检查。实际上,您让加载程序为您进行运行时检测。

为此,请将 XCode 项目中的体系结构设置从“标准 (armv6)”更改为“优化 (armv6 armv7)”

然后,在您的实现中,执行以下操作:

#if defined __ARM_NEON__
    // Code that uses NEON goes here
#else  // defined __ARM_NEON__
    // Fallback code without NEON goes here
#endif // defined __ARM_NEON__

您可以使用一个类似的宏来检查 (非 NEON)ARMv7 功能,我一时记不起。

如果您确实想进行运行时调度,请查看 sysctlbyname 函数。具体来说,我认为查找 HW_MACHINE_ARCH 参数可能对您有用。

Not exactly what you're asking, but one easy solution is to build your application fat, so that it contains executable code for both ARMv6 and ARMv7. If you do this, the appropriate code will run on the processor automatically, and you don't need to do any runtime checking. Effectively, you're letting the loader do the runtime detection for you.

To do this, change the Architectures setting in your XCode project from "Standard (armv6)" to "Optimized (armv6 armv7)"

Then, in your implementation, you do this:

#if defined __ARM_NEON__
    // Code that uses NEON goes here
#else  // defined __ARM_NEON__
    // Fallback code without NEON goes here
#endif // defined __ARM_NEON__

There is a similar macro that you can use to check for (non NEON) ARMv7 features, which I can't remember off the top of my head.

If you really want to do runtime dispatch, take a look at the sysctlbyname function in libc. Specifically, I think that looking up the HW_MACHINE_ARCH parameter may prove useful to you.

不知在何时 2024-08-16 06:49:11

我能想到的一种解决方法是检测 OpenGL ES 2.0 是否可用,因为较新的处理器可以实现这一点。

mobileorchard 上有一篇文章 关于如何去做。

One workaround I can think of, is detecting if OpenGL ES 2.0 is available, since the newer processors enable that.

There's an article at mobileorchard on how to do it.

风苍溪 2024-08-16 06:49:11

编辑:我已经撤回了这个答案,因为它留下了一个我后来意识到的明显漏洞:当我们在未来的某些硬件上得到未知的子类型时该怎么办?这不是面向未来的。此外,鉴于 Apple 对使用未记录的 API 采取零容忍态度,该 API 记录状态的不确定性也无济于事。

您应该使用 Stephen Canon 的答案并构建您的应用程序。可靠的、面向未来的运行时检测目前还不可行(我向你保证,令我沮丧的是)。

EDIT: I have withdrawn this answer, as it left out a glaring hole I realized later: what to do when we get an unknown subtype on some future hardware? THIS WAS NOT FUTURE-PROOF. Also, the uncertainty of the documented status of that API doesn't help, given Apple's zero tolerance on usage of undocumented APIs.

You should use Stephen Canon's answer and build your application fat. Reliable, future-proof runtime detection is not feasible at this time (to my dismay, I assure you).

我不咬妳我踢妳 2024-08-16 06:49:11

我知道这很糟糕,但我想到的最好的办法是检测设备是否支持视频录制。目前只有基于 ARM7 的 iPhone 和 iPod 设备支持它,因此我猜这是一种合法的方式。

为此,请将 UIImagePickerController 的 availableMediaTypesForSourceType 与 kUTTypeMovie 上的 isSourceTypeAvailable 结合使用。

I know this is crummy, but the best that comes into my mind is detect if the device supports video recording. Currently only the ARM7 based iPhone and iPod devices support it, hence its a legit way, I guess.

To do so, use UIImagePickerController's availableMediaTypesForSourceType in conjunction with isSourceTypeAvailable on kUTTypeMovie.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文