Search code examples
iosiphone-5

iPhone 5 migration big issues when xib is loading


In my project I have 3 xib files to support different devices. I need to support all devices: iPhone 3, iPhone 4, iPhone 5.

There are:

  • ViewController_iPhone_480.xib
  • ViewController_iPhone_568.xib
  • ViewController_iPad.xib

So, the main problem is that I need to detect which iPhone is being used and load the xib for it.

Very important: I need to check not just the iOS version. And also I don't need to check height or width of screen because it is very strange (for example, if some other device from Apple will have the same height or width in future - how does it help me?)

Have you got a method how to detect an iPhone 5 in code?

Thanks.


Solution

  • CGSize result = [[UIScreen mainScreen] bounds].size;
    result.height; // height in pixels
    result.width; // width in pixels
    

    Just check the result and make your decision upon that. iPhone 4 has 480 in height, and iPhone 5 has 568 in height.

    EDIT: you can check the current device your running on, before you look at height and width.

    NSString *deviceType = [UIDevice currentDevice].model;