Jeffsuke is not a pen.

🏊‍♂️🚴‍♂️🏃‍♂️💻📱

iOSバージョン分岐の話

f:id:jeffsuke:20150224180521j:plain

iOSのバージョンによる分岐を参考にバージョン分岐を実装したのだが、上手く行かなかったので対応策含めて書く。

iOSでは主に、[UIDevice currentDevice].systemVersionを用いてバージョン判定する方法と、NSFoundationVersionNumberマクロを使ってバージョン判定をする方法がある。前者はString, 後者はdoubleなため、数値比較を簡単に実施するにはNSFoundationVersionNumberの方がよいだろう。

if (NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_7_0) {
    // Above iOS7.0
}

*上記記事ではfloor()を用いて小数点以下を切り捨てているが、NSFoundationVersionNumberのリターンバリューもdoubleなので、その必要はない。 ちなみにマクロの中身はこんな感じ。

#if TARGET_OS_IPHONE
#define NSFoundationVersionNumber_iPhoneOS_2_0 678.24
#define NSFoundationVersionNumber_iPhoneOS_2_1  678.26
#define NSFoundationVersionNumber_iPhoneOS_2_2  678.29
#define NSFoundationVersionNumber_iPhoneOS_3_0  678.47
#define NSFoundationVersionNumber_iPhoneOS_3_1  678.51
#define NSFoundationVersionNumber_iPhoneOS_3_2  678.60
#define NSFoundationVersionNumber_iOS_4_0  751.32
#define NSFoundationVersionNumber_iOS_4_1  751.37
#define NSFoundationVersionNumber_iOS_4_2  751.49
#define NSFoundationVersionNumber_iOS_4_3  751.49
#define NSFoundationVersionNumber_iOS_5_0  881.00
#define NSFoundationVersionNumber_iOS_5_1  890.10
#define NSFoundationVersionNumber_iOS_6_0  992.00
#define NSFoundationVersionNumber_iOS_6_1  993.00
#define NSFoundationVersionNumber_iOS_7_0 1047.20
#define NSFoundationVersionNumber_iOS_7_1 1047.25
#endif

参考文献

iOSのバージョンによる分岐

NSFoundationVersionNumber and iOS Versions