Search code examples
iphoneobjective-ccocoa-touch

How to detect iPhone OS version in the app?


I would like to detect iPhone OS version in the app, can you post sample code as well. I tried using macro that didn't help.


Solution

  • You need to use the macros if you want conditional compilation:

     #if __IPHONE_8_0
     // Works on >= version 8.0
     #else
     // Works on < version 8.0
     #endif
    

    Or alternatively, to check at runtime, use:

    float ver = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (ver >= 8.0) {
        // Only executes on version 8 or above.
    }