Version Specific Preprocessor Macros

I have a preprocessor command to detect the version of iOS and support iCloud or not. I am wondering if the macro looks like this:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 //stuff #endif 

this will work if someone from iOS 4.x downloads the application from the application store, but it was compiled into / for iOS 5.x.

Since this will be evaluated at compile time, are these applications compiled on the device or how does it work? Is there a better way for the same result?

+4
source share
1 answer

You cannot use macros for this. Macros are evaluated at compile time, rather than at run time, for what you want to discover features / capabilities, such as iCloud support. (Otherwise, you will eventually turn it on, as you are compiling the iOS 5 SDK in all cases)

You should simply check for ubiquity methods that tell you if you can call them, which tells you if iCloud is supported, for example:

 if ([[NSFileManager defaultManager] respondsToSelector:@selector(isUbiquitousItemAtURL:)]) { // call it and do other iCloud stuff } 

Quick followup note re: your compilation question. Compilation is a process that turns your actual code into a binary file that runs on the device. This happens when you build in Xcode, and it only happens on your computer, never on Apple or on the device. That's why compilation time checks of versions will not work - by the time you send them to the device, the decision has already been made.

+7
source

All Articles