简体   繁体   English

在iOS 7上运行32位ARM,在iOS 8上运行64位

[英]Run 32-bit arm on iOS 7 and 64-bit on iOS 8

I am developing an app targeting iOS 5.1.1 through iOS 8. It is a universal binary containing arm64, armv7 and armv7s. 我正在开发通过iOS 8定位于iOS 5.1.1的应用程序。它是一个包含arm64,armv7和armv7s的通用二进制文件。 Now, arm64 will load on iOS 7 and greater (on supported devices) but I would like to force it to load only on iOS 8 (ie, make iOS 7 revert to loading armv7s). 现在,arm64将在iOS 7及更高版本(受支持的设备)上加载,但我想强制使其仅在iOS 8上加载(即,使iOS 7恢复为加载armv7s)。

Motivation: I need conditional compilation for some iOS 8 specific functionality for efficiency reasons. 动机:出于效率考虑,我需要针对某些iOS 8特定功能进行条件编译。 I am switching the entire rendering backend from OpenGL ES to Metal on iOS 8 and do not want to pay for any kind of dynamic dispatch between the two. 我正在将整个渲染后端从OpenGL ES切换到iOS 8上的Metal,并且不想为两者之间的任何动态分配付费。 The backend is a bunch of c-functions so a dynamic selection of API would require an extra layer of function pointers for everything. 后端是一堆c函数,因此动态选择API将需要为所有功能增加一层函数指针。 If arm64 is iOS 8 only I can conditionally compile the use of Metal using #ifdef __arm64__ . 如果arm64仅是iOS 8,则可以使用#ifdef __arm64__有条件地编译Metal的使用。

What I think might work: I am adding a conditional build setting for arm64 under "iOS Deployment Target". 我认为可能起作用:我在“ iOS部署目标”下为arm64添加了条件构建设置。 I have checked the build log and see that -miphoneos-version-min=8.0 is added for the arm64 build. 我已经检查了构建日志,并看到为arm64构建添加了-miphoneos-version-min=8.0 It works fine on iOS 8 and arm64. 它在iOS 8和arm64上运行良好。 For iOS 7 and arm64 I see two possible outcomes; 对于iOS 7和arm64,我看到两个可能的结果: 1) iOS 7 looks at the 64-bit binary, discards it as unsupported, and proceeds to load armv7s. 1)iOS 7查看64位二进制文​​件,将其丢弃为不受支持的文件,然后继续加载armv7s。 2) tries to load the 64-bit binary and crashes. 2)尝试加载64位二进制文​​件并崩溃。 The problem is that my only 64-bit device runs iOS 8 so I cannot test it. 问题是我唯一的64位设备运行iOS 8,因此我无法对其进行测试。

My question is if this works (perhaps someone have tried this before), or, if there is another solution to the problem. 我的问题是这是否可行(也许有人以前曾尝试过),或者是否有其他解决方案。

A screenshot of the conditional build setting for reference: 条件构建设置的屏幕快照供参考:

有条件的构建设置

Perhaps creation of 2 separate build schemes for iOS 7 & 8 (with different build settings for each scheme) can do what you want. 也许为iOS 7和8创建2个单独的构建方案(每种方案具有不同的构建设置)可以完成您想要的事情。

Update 更新

Sorry for misleading initial version of my answer. 抱歉,我的答案的初始版本有误导性。 Diving deeper into your question, I realized that you need to use a conditional compilation for a runtime-specific conditions. 深入探讨您的问题,我意识到您需要针对运行时特定的条件使用条件编译。 That is, you need to know at compile-time a runtime characteristic like iOS version running on a user's devices. 也就是说,您需要在编译时知道运行时特性,例如在用户设备上运行的iOS版本。 That's why you try to limit usage of iOS version to a certain architecture - in this case you will know that if the current arch is arm64 then device is running iOS 8. Sorry for not getting this earlier. 这就是为什么您尝试将iOS版本的使用限制为某种体系结构的原因-在这种情况下,您会知道,如果当前的架构是arm64,则设备正在运行iOS 8。

The problem is that an architecture is a hardware property ( iOS Support Matrix ). 问题在于架构是硬件属性( iOS支持矩阵 )。 The arm64 architecture is supported by iPhone 5S and iPhone 6, and at the same time iPhone 5S may have iOS 7. So if you limit arm64 to iOS 8 then you drop support of iOS 7 on iPhone 5S (what you've found by yourself). iPhone 5S和iPhone 6支持arm64体系结构,同时iPhone 5S可能具有iOS7。因此,如果将arm64限制为iOS 8,则将在iPhone 5S上放弃对iOS 7的支持(您自己发现的内容) )。

So I think the approach you've chosen won't work. 因此,我认为您选择的方法行不通。 Unfortunately I could not find any other ways to know a runtime characteristic like iOS version at compile time. 不幸的是,我在编译时找不到其他方式来了解运行时特性(如iOS版本)。

I understand that my answer doesn't solve your problem. 我了解我的答案无法解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM