Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

実行時にフレームワークバージョンで判定する

AppleのiOS7移行ドキュメントにも書いてあったのでNSFoundationVersionNumber を使うようにしている。

[UIDevice currentDevice].systemVersion を使うやり方もちらほら見かけるが、値が文字列であるためバージョンの大小判定としては実装を工夫する必要がある。NSFoundationVersionNumber を使う方が可読性もあり、実装も楽である。[UIDevice currentDevice].systemVersion は表示したりログとして残す方に使うと良いと思う。

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
    // Load resources for iOS 6.1 or earlier
} else {
    // Load resources for iOS 7 or later
}

iOS SDK 8時点での定義値。

#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
makoto_kw
本当は音楽、動画周りの技術ネタを投稿したい
http://makotokw.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした