简体   繁体   中英

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. 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).

Motivation: I need conditional compilation for some iOS 8 specific functionality for efficiency reasons. 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. The backend is a bunch of c-functions so a dynamic selection of API would require an extra layer of function pointers for everything. If arm64 is iOS 8 only I can conditionally compile the use of Metal using #ifdef __arm64__ .

What I think might work: I am adding a conditional build setting for arm64 under "iOS Deployment Target". I have checked the build log and see that -miphoneos-version-min=8.0 is added for the arm64 build. It works fine on iOS 8 and arm64. For iOS 7 and arm64 I see two possible outcomes; 1) iOS 7 looks at the 64-bit binary, discards it as unsupported, and proceeds to load armv7s. 2) tries to load the 64-bit binary and crashes. The problem is that my only 64-bit device runs iOS 8 so I cannot test it.

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.

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. 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.

The problem is that an architecture is a hardware property ( iOS Support Matrix ). 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).

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.

I understand that my answer doesn't solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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