Detect iphone 5 4 "screen

Possible duplicate:
How to detect iPhone 5 (widescreen devices)?

Is there a way to determine if the current device is iphone 5? More specifically, if it uses a new 4-inch screen?

+17
ios objective-c iphone xcode
Sep 21 '12 at 17:40
source share
4 answers

Use this

#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES) 
+44
Sep 23 2018-12-12T00:
source share

I think you should focus on your preferred display mode, not iPhone5 detection. Who knows what devices Apple will produce, but if your software supports this mode, it will be reliable in the future.

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

In the future, people may want to change their preferred display mode on the fly. For example, disconnect AppleTV from 720p TV and connect to 1080p without restarting the application, of course.

+17
Sep 21 '12 at 17:48
source share

Add this code to your source code:

 if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){ if(UIScreenOverscanCompensationScale==1136/640){ //move to your iphone5 storyboard [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)]; } else{ //move to your iphone4s storyboard [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)]; } } 

This was the answer posted by me in another question here .

+4
Sep 21 '12 at 20:38
source share

Add this code to the application:

 if ([UIScreen mainScreen].scale == 2.f && screenHeight == 568.0f) {// iPhone 5 code} else {// previous version code} 
+2
Sep 23 '12 at 8:13
source share



All Articles