Вопрос

I am using the following code (in AppDelegate) to detect if the device is iPhone 5

bool isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));

it returns false always. this is not the first time I used that code. eventhe NSLog for that returns {320, 480}

NSLog(@"%@",NSStringFromCGSize([[UIScreen mainScreen] bounds].size));

NOTE: The app was for iPad only and then I made it universal. so I will have 2 storyBoards that is why I need the detection code.

Thanks

Это было полезно?

Решение 7

Finally I figure it out.

Solution

Because the App was for iPad only the Default-568h@2x.png doesn't exist in the project. so after adding it all work properly.

Note and I dont need the above code because after making the app universal in the xcode project setting there is a part for iPhone/iPod Deployment info configurations (icons,mainStoryBorad,default screens ....) where I can setup the iPhone5 storybord after adding it to the project.

Другие советы

This should work mate,

 bool isiPhone5 = ([[UIScreen mainScreen] bounds].size.height == 568);

and make sure you use 4-inch simulator

enter image description here

I used the following code. You can try this:

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

Then you can do:

if (IS_IPHONE_5) {
    //Do your stuff
}

Hope this helps.

#define IS_iPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

if(IS_iPHONE_5)
{
    //Do something
}
else
{

}

To identify iphone 5 try this

  if( [[UIScreen mainScreen]bounds].size.height == 568){

    //iphone 5 
 }
  else
 {
    // less than iphone 5 
 }

try this

#include <sys/sysctl.h>

-(NSString *)getModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
return deviceModel;
}

this Link should help

See Below One

if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){
if( [[UIScreen mainScreen]bounds].size.height == 568){

  //iPhone5 Device
}
else
{
    // Normal iPhone device
}

}

EDIT: see same thread

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top