0

I am developing an universal App and I want to support iOS 6, iOS 5 and iPhone 5. I am planing to do this with different Storyboards but the question is how to switch Storyboards in the AppDelegate. I tried this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {


        float currentVersion = 6.0;

        CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= currentVersion == NO) {

            if (iOSDeviceScreenSize.height == 480)
            {

                UIStoryboard *ios5iphone = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone-ios5" bundle:nil];


            }

            else
            {UIStoryboard *ios5iphone = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad-ios5" bundle:nil];}

        }
return YES;

    }

I have 4 Storyboards (iPhone 4/5 with Autolayout for iOS 6, iPad with Autolayout for iOS 6,iPhone 4 for ios 5 and iPad for iOS 5)

My problem is how to switch Storyboards before application launch.

Error:

2012-11-18 13:42:42.471 iEveryTech[22902:c07] Unknown class Firs in Interface Builder file.
2012-11-18 13:42:42.494 iEveryTech[22902:c07] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint'
*** First throw call stack:
(0x1632052 0xfaed0a 0x15daa78 0x15da9e9 0x43b7d7 0x43b9af 0x43b6b7 0x33c36d 0x1e3e2c 0x1e43a9 0x1e45cb 0x1ffb89 0x1ff9bd 0x1fdf8a 0x1fde2f 0x1fbffb 0x1fc85a 0x1e5fbf 0x1e621b 0x1e70f1 0x155fec 0x15b572 0x15572b 0x144bc2 0x144ce2 0x144ea8 0x14bd9a 0x11cbe6 0x11d8a6 0x12c743 0x12d1f8 0x120aa9 0x17c5fa9 0x16061c5 0x156b022 0x156990a 0x1568db4 0x1568ccb 0x11d2a7 0x11ea9b 0x228d 0x21b5 0x1)
terminate called throwing an exception(lldb) 
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98
  • Put the `return` statement at the end of the method. And please clarify what is your problem. – Mat Nov 18 '12 at 11:37
  • @Mat My problem is how to switch Storyboards – David Gölzhäuser Nov 18 '12 at 12:03
  • 1
    Yes ok, but i mean what is the problem with your code. What's happen when you run your code? Can you see at least one controller or not? Have you put the return statement at the end? – Mat Nov 18 '12 at 12:09
  • @Mat I dont see a controller, the simulator crashes everytime the app loads up, this is the same error like when I check "use Autolayout" in iOS 5 I think the code is false. Do you have any idea? – David Gölzhäuser Nov 18 '12 at 12:15
  • So please at least post the error message or anything that could be useful to understand your problem. – Mat Nov 18 '12 at 12:23

2 Answers2

3

Based on your error, it seems that you're targeting for a iOS version < 6. Probably you're using the Main Storyboard setting in the Target summary settings. As you can see here, he does exactly what you want to achieve.
Otherwise you can use two target for different versions.

Community
  • 1
  • 1
Mat
  • 7,613
  • 4
  • 40
  • 56
0

This was the soultion of my problem

    #import "AppDelegate.h"

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:(v) options:NSNumericSearch] != NSOrderedAscending)

@interface AppDelegate ()
@property (strong, nonatomic) UIViewController *initialViewController;
@end

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

    UIStoryboard *mainStoryboard = nil;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")==NO)


            if (iOSDeviceScreenSize.height == 480)
            {

                mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone-ios5" bundle:nil];
    } else {
        mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad-ios5" bundle:nil];
    }

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))


        if (iOSDeviceScreenSize.height == 480)
        {

            mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
        } else {
            mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
        }


    self.initialViewController = [mainStoryboard instantiateInitialViewController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = self.initialViewController;
    [self.window makeKeyAndVisible];



    return YES;

Thanks to @Mat!

David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98