Xcode iPhone device plays different version from iPhone Simulator - ios

I created an iPhone 6 class and iPhone 5 class. In app delegate I used the following code for each size to be recognized...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGSize iosScreenSize = [[UIScreen mainScreen] bounds].size;
if (iosScreenSize.height ==568) {
UIStoryboard *iPhone5 =[UIStoryboard storyboardWithName:#"iPhone5" bundle:nil];
UIViewController *initialViewController =[iPhone5 instantiateInitialViewController];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
if (iosScreenSize.height == 667) {
UIStoryboard *iPhone6 = [UIStoryboard storyboardWithName:#"iPhone6" bundle:nil];
UIViewController *initialViewController =[iPhone6 instantiateInitialViewController];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
return YES;
}
The simulator picks up iPhone 5 storyboard when needed and iPhone 6 storyboard when needed however, the device picks the wrong storyboard. When I use the iPhone 6 device, Xcode plays my iPhone 5 storyboard on iPhone 6 device. How do I get Xcode to play my iPhone 6 storyboard on iPhone 6 device?

Related

Xcode 7.1 iPad PRO simulator stretching iPad Air 2 app?

Today I updated from Xcode 7.0.1 to 7.1.1 just for iPad Pro simulator. The iPad Pro resolution is different from all other iPads so is the iPad Pro simulator just stretching my game to fit into iPad Pro? The iPad Pro simulator, my app doesn't have a stretched look though it looks great. I'm confused, is the simulator just playing a stretched version of iPad Air 2 or if I were to use iPad Pro device and run the app, i'd see also a perfectly fitted iPad Pro app running?
The iPad PRO is loading the code from iPad AIR, iPad AIR 2 and iPad RETINA simulators
For anyone still having above issues here's the solution I found:
In AppDelegate.m, in the application didFinishLaunchingWithOptions code, use the following code:
if (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && [UIScreen mainScreen].bounds.size.height == 1366))
{
UIStoryboard *iPadPRO = [UIStoryboard storyboardWithName:#"iPadPRO" bundle:nil];
UIViewController *initialViewController =[iPadPRO instantiateInitialViewController];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)] && [[UIScreen mainScreen] scale] == 2){
UIStoryboard *iPadRetina = [UIStoryboard storyboardWithName:#"iPadRetina" bundle:nil];
UIViewController *initialViewController =[iPadRetina instantiateInitialViewController];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}

Why won't my storyboard work on the iphone?

In the app delegate I have this written to determine which storyboard will be opened depending on the screen size,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [self grabStoryboard];
// show the storyboard
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
- (UIStoryboard *)grabStoryboard {
UIStoryboard *storyboard;
// detect the height of our screen
int width = [UIScreen mainScreen].bounds.size.width;
if (width == 480) {
storyboard = [UIStoryboard storyboardWithName:#"iphone4" bundle:nil];
// NSLog(#"Device has a 3.5inch Display.");
} else {
storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
// NSLog(#"Device has a 4inch Display.");
}
return storyboard;
}
The app opens landscape on the device.
This will properly choose between a 3.5 inch device and a 4 inch device in the simulators, but won't properly display in an actual 3.5 inch device. In Xcode 6 it opens the correct storyboard for the 4s or the 5, 6 ,6+ depending on the width of the screen but when tested on an actual Iphone 4s (with ios 7.1.1) the storyboard configured for 4 inch devices is displayed.

Using multiple Storyboards in Xcode

I have created 5 extra Storyboards and I have deleted the main storyboard. This is because I would like to have 5 separate storyboards for the iPhone and iPad to match 5 different screen sizes. So far I have one for the iPhone 3.5 inch, one for the iPhone 4 inch, one for the iPhone 4.7 inch, one for the iPhone 5.5 inch and one for the iPad. I have put the code bellow in to link it all up and make it work. However, it doesn't work when you try and build the project. There is no errors but lets say I go into the iPhone 3.5 inch storyboard and I add a UIViewController and a Button or label, then when you build the project it goes to your launch screen and then it doesn't do anything from there. I have put the starting arrow in at the UIViewController but I cannot get anything to come up apart from the launch screen. I have tried this on all the storyboards and their simulators. I am wondering if I have missed something out in the code but I am not sure.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = nil;
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPad" bundle:nil];//iPad
} else {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (screenSize.height == 480){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone4S" bundle:nil];//iPhone 3.5inch
} else
if (screenSize.height == 568){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone5/5C/5S" bundle:nil];//iPhone 4inch
}
else
{ if (screenSize.height == 667){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone6" bundle:nil];//iPhone 4.7inch
} else
if (screenSize.height == 736){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone6Plus" bundle:nil];//iPhone 5.5inch
} else
//default storyboard
storyboard = [UIStoryboard storyboardWithName:#"Main.Storyboard" bundle:nil];
}
}
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
Find your info.plist file in your project and remove the line called "Main storyboard file base name".
Also, you forgot to create the window (credits to rdelmar).
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
I strongly advise you to look into Auto Layout and Size Classes. Using these two, you can support all screen sizes within one single Storyboard. It's a bit hard to get in the beginning, but it'll definitely be worth it in the long run.
There's a video about this from the most recent WWDC called Building Adaptive Apps with UIKit.

How can I load different storyboards depending on the device?

I am trying to:
detect device (iPhone 3.5", iPhone 4", iPad, ect)
load a different storyboard depending on what device and what size the application is running on.
I have watched some tutorials but I am still not getting it, can someone please type/show what code needs to go in the app delegate to achieve these goals.
Thanks!
Try something like this in your app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIStoryboard *storyboard = nil;
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568.0f)
{
storyboard = [UIStoryboard storyboardWithName:#"iPhone5s" bundle:nil];
}
else
{
storyboard = [UIStoryboard storyboardWithName:#"iPhone4" bundle:nil];
}
}
else
{
storyboard = [UIStoryboard storyboardWithName:#"iPad" bundle:nil];
}
[window setRootViewController:[storyboard instantiateInitialViewController]];
[window makeKeyAndVisible];
}

iOS >> Setting UIWindow in AppDelegate When Using Multiple Storyboards

I wish to create an app with multiple storyboards to support iPhone5, iPhone4 (and below) and iPad screens.
I did the following:
I created 3 storyboards, one per each setting.
I cleared the "main storyboard" field in the project interface.
I cleared the "Main storyboard file base name" field in the app info.plist file.
I entered the following code to the AppDelegate "didFinishLaunchingWithOptions" method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard* appStoryboard = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if (IS_IPHONE_5) //a macro capturing the screen size
{
appStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone5" bundle:nil];
}
else
{
appStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone4" bundle:nil];
}
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
appStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
}
UIViewController* viewController = [appStoryboard instantiateInitialViewController];
[self.window setRootViewController:viewController];
[self.window makeKeyAndVisible];
return YES;
}
The application is running and not crashing, but I get a black screen.
What am I missing / doing wrong?
You didn't initialize the window.
Just add
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Resources