In previous iOS versions I used NSFoundationVersionNumber
to detect the iOS version:
#define IS_IOS10orHIGHER (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max)
#define IS_IOS9orHIGHER (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_8_3)
#define IS_IOS8orHIGHER (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
#define IS_IOS7orHIGHER (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
#define IS_IOS6orHIGHER (floor(NSFoundationVersionNumber) >= NSFoundationVersionNumber_iOS_6_0)
...
Now I would to do the same for iOS 11, but I was not able to find the correct NSFoundationVersionNumber
. The docs show NSFoundationVersionNumber_iOS_9_x_Max
to be the latest.
So, how is the correct NSFoundationVersionNumber
to detect if iOS 11 is used?
In Objective-C, you need to check the system version and perform a comparison. [[NSProcessInfo processInfo] operatingSystemVersion] in iOS 8 and above.
Android DevicesTouch "Settings," then touch "About Phone" or "About Device." From there, you can find the Android version of your device.
If you are using Xcode 9 or better, you can use the @available
attribute:
if (@available(iOS 11.0, *)) {
NSLog(@"newest");
} else {
NSLog(@"not newest");
}
In Swift, it's the same, but spelled #available
instead of @available
.
The reason that this is a better way to do this than the other methods is because the compiler is aware of it, and will suppress availability warnings appropriately. So in the example above, you can use APIs that were introduced in iOS 11.0 within the if
block without being warned about those APIs being unavailable to your project's deployment target.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With