Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having issue with detect iPhone 6/Plus on simulator

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 !

like image 854
iOS.Lover Avatar asked Sep 28 '14 09:09

iOS.Lover


People also ask

How do I add a device to Xcode simulator?

Open Xcode and click Menu > Xcode > Preferences > Select Components, and then choose the simulator version you want to download. When a simulator is opened from AppStudio, AppStudio Player automatically installs (if necessary) and opens in it.

How do you choose a simulated device as a destination?

For iOS, tvOS, and watchOS apps, you can choose a simulated device, under [Platform] Simulators, from the run destination menu next to the scheme menu in the toolbar. To add additional simulators of a product family running older versions of the operating system, choose Add Additional Simulators.

How do I find my iPhone using Xcode?

Open up a project in Xcode and click on the device near the Run ▶ button at the top left of your Xcode screen. Plug your iPhone into your computer. You can select your device from the top of the list. Unlock your device and (⌘R) run the application.


2 Answers

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 :

enter image description here

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)
like image 133
iOS.Lover Avatar answered Sep 22 '22 14:09

iOS.Lover


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)
like image 40
tsuyoski Avatar answered Sep 21 '22 14:09

tsuyoski