BrownEye
BrownEye

Reputation: 979

Xcode detect iOS version and show storyboard accordingly

I want to show one storyboard to my iOS6 users and another to iOS7 users. How can I do this?

Upvotes: 2

Views: 5904

Answers (3)

Greg
Greg

Reputation: 33650

You can get the iOS version using this code:

[[UIDevice currentDevice] systemVersion]

For example, to detect iOS 6, you could do something like:

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

Then, to load different storyboards for iOS 6 and 7, you would do something like:

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

EDIT: as noted in the other answers, an arguably better way to detect iOS version is to use the NSFoundationVersionNumber, as no string parsing of the systemVersion is needed.

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
    myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_6" bundle:nil];
} else {
    myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_7" bundle:nil];
}

Upvotes: 3

danypata
danypata

Reputation: 10175

You can try something like this in AppDelegate (very important)

 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]];
 }

Upvotes: 0

Mike Pollard
Mike Pollard

Reputation: 10195

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
    //load and show ios6 storyboard
}
else {
    //load and show ios7 storyboard
}

Upvotes: 5

Related Questions