Reputation: 115
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.
Upvotes: 9
Views: 12802
Reputation: 1311
In addition to the compile-time checks given in other answers, you can use the Swift's @available
attribute to add new functionality starting at a specific OS version.
if (@available(iOS 13.4, *)) {
// Only executes above version 13.4.
}
Here's a decent summary of the evolution of OS version checking and usage.
Upvotes: 0
Reputation: 311436
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.
}
Upvotes: 35