utahwithak utahwithak - 1 year ago 113
iOS Question

Version specific preprocessor macros

I have a preprocessor command for detecting the version of iOS and supporting iCloud or not. What I am wondering is if a macro like so:


will this work if someone with iOS 4.x downloads the app from the app store but it was compiled on/for iOS 5.x.

Since this would be evaluated on compile time are the apps compiled on the device or how does that work? Is there a better way for the same result?

Answer Source

You can't use macros for this. Macros are evaluated at compile time, and not at runtime, which is what you want for feature/capability detection, like iCloud support. (Otherwise you'll end up with it enabled since you're compiling against the iOS 5 SDK in all cases)

You should just test for the presence of the ubiquity methods, which tell you whether you can call them, which tells you whether iCloud is supported, e.g.:

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

Quick followup note re: your question about compiling. Compilation is the process that turns your actual code into the binary that runs on the device. This happens when you do Build in Xcode, and it happens on your machine only, never at Apple or on the device. This is why compile-time checks for version numbers won't work-- by the time you send it to a device, the decision would have already been made.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download