Create bootable iPad stock in a universal app

I set up BOOL

called isUsingiPad

to detect when my user is using iPad. I used this for this:

UIDevice* userDevice = [UIDevice currentDevice];
if (userDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    isUsingiPad = YES;
}

      

When my app starts first, it checks if my account has passed. If it then dispatches the user to the main view controller of my app. However ... when the logged in user (who is using an iPad) logs in, closes the app, and then reopens it, they are sent to the iPhone nib instead of the iPad. I have 2 feathers for each kind in my application. One for the iPhone and one for the iPad. There is one view controller controlling each set of 2. I have already set up the code to handle it, whether it be iPhone or iPad. My question is, what should I add to make sure the user gets to the iPad every time? Where can I add this? I can edit this question to include any code needed. Thanks in advance.

Edit: updated method -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:

.

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


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

UIDevice* userDevice = [UIDevice currentDevice];
if (userDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    isUsingiPad = YES;
}

if (!isUsingiPad) {
    self.viewController= [[PassportAmericaViewController alloc] initWithNibName:@"PassportAmericaViewController" bundle:nil];
} else {
    self.viewController = [[PassportAmericaViewController alloc] initWithNibName:@"PassportAmericaViewController-iPad" bundle:nil];
}

self.window.rootViewController = self.viewController;

[self.window addSubview:navigationController.view];

[self.window makeKeyAndVisible];

return YES;
}

      

+3


source to share


2 answers


This is what Apple uses in app templates to achieve this, it is implemented in your AppDelegates

applicationDidFinishLaunchingWithOptions

:

Now, after making sure your user is returned to the correct screen every time, depending on your installation, you can initialize this to viewDidLoad

or viewDidAppear

.



 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

      

+1


source


In order to dynamically load iPad / iPhone nibs into universal apps, you must use the following naming conventions: -

  • iPhone - MyNibName.xib
  • iPad - MyNibName ~ ipad.xib


By doing it like this, you don't need to go through manual downloads or instructions.

+1


source







All Articles