Grymjack
Grymjack

Reputation: 539

xcode simulator keeps changing hardware device modes when trying to test different storylines

I'm having some weirdness with my simulator and I'm hoping that someone can help me. The code below is in my AppDelegate. I have different storyboards depending on which device is running. The device detection code seems to work fine, but I'm having problems keeping the simulator Hardware->Device where I want.

  1. The project setting is 'Universal' and the simulator is set to iPhone. The simulator will change itself to the iPhone simulator and run as an iPhone.
  2. Project setting to iPad, simulator to iPad, runs as iPad. Set project back to universal, simulator back to iPhone, the simulator resets itself back to iPad and runs the code as an iPad.
  3. Project setting to iPhone, leave simulator on iPad. Runs as a iPhone app on the iPad??

....and multiple different variations. Tried restarting the Mac and xcode multiple times, no effect. If I reset the simulator and run the project icon on the simulator rather than through xcode, the simulator stays in the Hardware mode I put it in. Any thoughts out there??


-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // testing for iPad detection
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        // setting storyboard name
        [[Data sharedData] setStoryboardName:@"MainStoryboardPad"];

        // going to the 4" screen story board and settng it as the root controller
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboardPad" bundle:nil];
        UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Intro Screen"];

        // making that tab controller the root controller
        self.window.rootViewController = viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    else
    {
        // detecting screen size
        if (([UIScreen mainScreen].scale == 2) && ([[UIScreen mainScreen] bounds].size.height == 568))
        {
            // setting storyboard name
            [[Data sharedData] setStoryboardName:@"MainStoryboard40"];

            // going to the 4" screen story board and settng it as the root controller
            self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard40" bundle:nil];
            UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Intro Screen"];

            // making that tab controller the root controller
            self.window.rootViewController = viewController;
            [self.window makeKeyAndVisible];
            return YES;
        }
        else
        {
            // setting storyboard name
            [[Data sharedData] setStoryboardName:@"MainStoryboard35"];

            // going to the 3.5" screen story board and settng it as the root controller
            self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard35" bundle:nil];
            UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Intro Screen"];

            // making that tab controller the root controller
            self.window.rootViewController = viewController;
            [self.window makeKeyAndVisible];
            return YES;
        }
    }
}

Upvotes: 3

Views: 380

Answers (1)

Greg
Greg

Reputation: 9168

If I understood your question correctly, the problem you're having is you're having difficulty running your app in the simulator as an iPad, because it keeps changing back to iPhone. This is because you need to select which simulator you want to run the app in in Xcode, in the top toolbar:

Click on the menu

Choose the simulator you want to run as

After doing that, click run and the iOS simulator you chose should open and run your app.

Upvotes: 1

Related Questions