2013-10-04 32 views

回答

3

您可以使用此代码获取iOS版本:

[[UIDevice currentDevice] systemVersion] 

例如,要检测的iOS 6,你可以这样做:

if ([[UIDevice currentDevice].systemVersion hasPrefix:@"6"]) { 
    // ... 
} 

然后,加载的iOS不同的故事板6和7,你会做这样的事情:

if ([[UIDevice currentDevice].systemVersion hasPrefix:@"6"]) { 
    myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_6" bundle:nil]; 
} else { 
    myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_7" bundle:nil]; 
} 

编辑:正如在其他答案中指出的,检测iOS版本的一种更好的方法是使用NSFoundationVersionNumber,因为不需要字符串解析systemVersion。

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { 
    myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_6" bundle:nil]; 
} else { 
    myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_7" bundle:nil]; 
} 
5
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { 
    //load and show ios6 storyboard 
} 
else { 
    //load and show ios7 storyboard 
} 
+0

不能正常在iOS 6.1.3,因为6.1.3版本的iOS它的浮点值的工作是993.0和NSFoundationVersionNumber_iOS_6_1对于6.1.3版本来说是992.0 som,你将使WRONG假设它是iOS 7或更高版本 –

+0

@NikolayShubenkov - 我从iOS7转换指南中获取了这些代码。 (https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/TransitionGuide/SupportingEarlieriOS.html#//apple_ref/doc/uid/TP40013174-CH14-SW1 –

+0

@NikolayShubenkov-有趣的是,我明白了。 .. #define NSFoundationVersionNumber_iOS_6_0 993.00 #define NSFoundationVersionNumber_iOS_6_1 993.00在NSObjCRuntime.h –

0

您可以尝试在AppDelegate中(非常重要)是这样的

UIStoryboard *storyboard = nil; 
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { 
    storyboard = [UIStoryboard storyboardWithName:@"iOS7_AND_ABOVE" bundle:[NSBundle mainBundle]]; 
} else { 
    storyboard = [UIStoryboard storyboardWithName:@"iOS_below_7" bundle:[NSBundle mainBundle]]; 
} 
+0

Xcode似乎不知道NSFoundationVersionNumber_iOS_6_1是什么,它只知道5_1。这是怎么回事? –

+0

@Chase Robers使用iOS SDK 7 NSFoundationVersionNumber_iOS_6_1仅在IOS 7 SDK上定义 – DarthMike

+0

我的苹果机太老了让我升级操作系统到xcode更新所需的最低版本,所以我只是运气不好... –