Reputation: 6051
I am trying to build a version of my app specifically for iPhone 6 and 6 Plus , whereas I don't have any hardware , I have to test on the simulator ! but it seems , simulator has a strange bug ! first and for most I get screen resolutions and scales , by this code :
UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
so here is how detect iPhone 6 and 6Plus (Portrait mode):
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 736)
the problem is ! when I lunch my app on iPhone6/Plus simulator , compiler gives me the sceen information of iPhone 4" display :
2014-09-28 12:32:08.153 WOD[2924:42290]
Screen bounds: {{0, 0}, {320, 568}}, Screen resolution: <UIScreen: 0x7fa15be0f9b0; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x7fa15bd0d4a0;
size = 640.000000 x 1136.000000>>, scale: 2.000000, nativeScale: 2.000000
But it works fine on new project ! (I cannot create a new project and start over again !).
I cleaned code
, delete build folder
, change project's name
,and reset Simulator contents setting
but still gives me the information of 4" display ! .
I have checked this Q/A but answers require a real device !
Upvotes: 14
Views: 10051
Reputation: 6051
The main reason I faced with this problem was I build my application with Xcode 5
and open it with Xcode 6
Solution :
Add Launch Image for Retina HD 5.5 and 4.7 :
Now you can detect iPhone 6/Plus on simulator without having a real device :
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)
Upvotes: 21
Reputation: 644
Just in case you need to detect iPhone 6/6Plus in landscape, use this.
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)
Upvotes: 2