-1

I have iOS app and I´m using the size directives explained at this post.

I'm testing using iOS simulator on the latest Xcode (6.4) version. When I run my project, and select iPhone 4s on the device selection, the project runs with the correct detection message and the correct Storyboard; The same if I run using iPhone 5 and iPhone 5s. But when I select the iPhone 6 or 6 Plus, the detection and the console log that i have put at this part detects the iPhone as Iphone 5 and shows the storyboard for iPhone 5. I try to detect the resolution (in points of the CGRect height and show on the console log using NSLog, but no matters that the simulator display a window with te correct size, in the log appear the resolution size of an iphone 5.

There is the code when i define the directives:

#define IS_IPHONE_4 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)480) < DBL_EPSILON)
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE_6P (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)736) < DBL_EPSILON)

And there is the code when i detect the device:

//Para detectar screen size
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

if (IS_IPHONE_4)
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"4sStoryboard" bundle:[NSBundle mainBundle]];
    UIViewController *vc =[storyboard instantiateInitialViewController];
    self.window.rootViewController = vc;
    NSLog(@"iPhone 4 storyboard loaded up.");
}

else
{
    if(IS_IPHONE_5)
    {
    UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UIViewController *vc2 =[storyboard1 instantiateInitialViewController];
    self.window.rootViewController = vc2;
    NSLog(@"iPhone 5 storyboard loaded up.");
    }
    else
    {
        if (IS_IPHONE_6)
        {
            UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"6Storyboard" bundle:[NSBundle mainBundle]];
            UIViewController *vc2 =[storyboard1 instantiateInitialViewController];
            self.window.rootViewController = vc2;
            NSLog(@"iPhone 6 storyboard loaded up.");
        }
        else
        {
            if (IS_IPHONE_6P)
            {
                UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"6pStoryboard" bundle:[NSBundle mainBundle]];
                UIViewController *vc2 =[storyboard1 instantiateInitialViewController];
                self.window.rootViewController = vc2;
                NSLog(@"iPhone 6 plus storyboard loaded up.");
            }

        }
    }

And this is the exit of my log no matter if is iphone 5 or 6 or 6plus, The detection of iPhone 4s works normally:

 2015-09-04 15:44:55.823 denuncia[1737:156925] iPhone 5 storyboard loaded up.

How I can ressolve this issue? I have working arrond this a long time and soon can have some troubles... I really appreciate your help.

Community
  • 1
  • 1
  • Can you post code on how you are detecting the device? – Siriss Sep 04 '15 at 19:38
  • `Option 1)` Show the code for detecting the device and the code for selecting a storyboard. `Option 2)` Update your app to a single storyboard that adapts to all devices using size classes and auto-layout. `Note:` You should be aware that your code will likely fail on an iPad with slide over in iOS 9 (and even fail if Apple allow slide over on larger iPhones) – Robotic Cat Sep 04 '15 at 20:05
  • I post the codes, and i expected that only works on iphones not in ipads – Max Clow Reed Sep 04 '15 at 20:53

1 Answers1

0

I am using this code with no trouble at all. Try it and if it does not work write me a comment!

#define IS_IPHONE_4      ([UIScreen mainScreen].bounds.size.height == 480)
#define IS_IPHONE_5      ([UIScreen mainScreen].bounds.size.height == 568)
#define IS_IPHONE_6      ([UIScreen mainScreen].bounds.size.height == 667)
#define IS_IPHONE_6P     ([UIScreen mainScreen].bounds.size.height == 736)

Yes, simple as that!

Cheers

MasterRazer
  • 1,377
  • 3
  • 16
  • 40