开发者

How to detect iPhone OS version in the app?

开发者 https://www.devze.com 2022-12-13 19:30 出处:网络
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 compilati

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消