I would like to detect开发者_如何学Go iPhone OS version in the app, can you post sample code as well. I tried using macro that didn't help.
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.
}
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.
精彩评论