Wongzigii Wongzigii - 1 year ago 124
Objective-C Question

Can not compare systemVersion in iOS 10

#define kIOS8_OR_LATER \
([[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending)

Why the comparison between iOS 8.0 and 10 not work?

if (kIOS8_OR_LATER) {
} else {


  • Simulator iOS 10 (14A345)

  • Real device iPhone 6s iOS 10.0.1 (14A403)


  • Version 8.0 (8A218a)

The console keeps logging 0, but works fine in iOS 9.

Answer Source

A normal string comparison looks at one character at a time. A 1 is ordered before an 8. So you need to make the comparison numeric:

#define kIOS8_OR_LATER \
    ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending)

Then the comparison is between 8 and 10.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download