2

I have this iPhone or iPhone 5 conditional statement in a locationUpdate: method.

This code works:

- (void)locationUpdate:(CLLocation *)location {
    //locLabel.text = [location description];

#ifdef DEBUG    
    NSLog(@"auth status is %u", [CLLocationManager authorizationStatus]);
#endif


                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
                OffersViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewController"];
                [self.navigationController pushViewController:lvc animated:NO];


}

but when the iphone5 conditional code. It fails. The app doesn't crash but just remains on the view controller (RootViewController) and doesn't push to either the OffersViewController or the OffersViewControlleriPhone.

- (void)locationUpdate:(CLLocation *)location {
    //locLabel.text = [location description];

#ifdef DEBUG    
    NSLog(@"auth status is %u", [CLLocationManager authorizationStatus]);
#endif

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);

            if(result.height == 960) {
                NSLog(@"iPhone 4 Resolution");

                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
                OffersViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewController"];
                [self.navigationController pushViewController:lvc animated:NO];


            }
            **else if(result.height == 1136) {
                NSLog(@"iPhone 5 Resolution");

                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
                OffersViewControlleriPhone5 *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewControlleriPhone5"];
                [self.navigationController pushViewController:lvc animated:NO];

            }**
        }
        else {
            NSLog(@"Standard Resolution");

            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
            OffersViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewController"];
            [self.navigationController pushViewController:lvc animated:NO];


        }
    }

}

it seems to be the else if statement for the iPhone5 that's the problem. It doesn't work even if I change the OffersViewControlleriPhone5 to OffersViewController.

thanks for any help

hanumanDev
  • 6,592
  • 11
  • 82
  • 146
  • You really shouldn't be doing things like that, checking the screen size, since anything can change it, calls make the status bar bigger, rotation will swap them, etc... – jjv360 Feb 25 '13 at 13:53
  • @jjv360 I found this code to check for iPhone vs iPhone5. What's a better approach to testing which device is used? thanks. – hanumanDev Feb 25 '13 at 13:55
  • 1
    Well this is probably the best method for displaying different views based on screen size, but normally views should flow so that they scale themselves to fit any screen... That way you only have one view to manage and updating for different devices is really easy... – jjv360 Feb 25 '13 at 13:57
  • See also: http://stackoverflow.com/questions/12446990/how-to-detect-iphone-5-widescreen-devices – Ben Flynn Feb 25 '13 at 13:58
  • @jjv360 thanks! I had some views that when viewed on the iPhone5 were displaying differently so i went with this option. – hanumanDev Feb 25 '13 at 14:27

1 Answers1

0

just figured it out. I had a } that closed the if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ before the if(result.height == 1136) { condition is reached.

hanumanDev
  • 6,592
  • 11
  • 82
  • 146