-1
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        CGSize result = [[UIScreen mainScreen] bounds].size;
            //NSLog(@"phonesize%@",result);
        if(result.height > 500){
                NSLog(@"iPhone 5");      
        }
        else{
                NSLog(@"iPhone 4");

            }
    }

My Mac OS is 10.7.2 and Xcode 4.5.2.I used above code to find device is iPhone 4 or iPhone 5 It is giving iPhone4 when i uses iPhone5.I did set launch image and icon image. Is there anything else i missed out?

4

4 回答 4

1

Make sure you have a PNG file named Default-568h@2x.png in your project.

于 2013-07-18T10:29:00.223 回答
0

You need to scale the result you got as per the screen's scale scale and then check ...

 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");
        }
        if(result.height == 1136) {
            NSLog(@"iPhone 5");
        }
    }
    else{
        NSLog(@"Standard Resolution");
    }
}
于 2013-07-18T07:47:42.463 回答
0

Try this code instead its tested.

if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)
    {
      //device is iPhone

      CGRect screenBounds = [[UIScreen mainScreen] bounds];
      if (screenBounds.size.height == 568) {
        //device is iphone 5
        //add storyboard/Xib that have large screen (320*568)
      } else {
          //device is iphone 4
          //add story board/Xib that have small screen (320*480)

      }

    }
else
    {
      //device is iPad
    }
于 2013-07-18T08:03:43.910 回答
0
  if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
      CGRect screenBounds = [[UIScreen mainScreen] bounds];
      if (screenBounds.size.height == 568) 
      {
         //iphone 5

      else 
      {

        //iphone 4


      }
   }
else
    {
      //iPad
    }

Try this one might be helpful to you...

于 2013-07-18T08:06:38.057 回答