在模拟器上检测iPhone 6 / Plus时遇到问题

时间:2014-09-28 09:11:40

标签: ios objective-c iphone xcode

我正在尝试专门为iPhone 6和6 Plus构建我的应用程序版本,而我没有任何硬件,我必须在模拟器上进行测试!但似乎,模拟器有一个奇怪的错误!首先,我通过以下代码得到屏幕分辨率和比例:

    UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
      NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);

所以这里是如何检测iPhone 6和6Plus(纵向模式):

#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 667)

#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 736)
问题是!当我在iPhone6 / Plus模拟器上吃午餐时,编译器会给我一些iPhone 4“显示屏的信息:

    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

但它在新项目上运作良好! (我无法创建一个新项目并重新开始!)。 我cleaned codedelete build folderchange project's name和重置Simulator contents setting,但仍然向我提供4“显示的信息!。

我已经检查了这个Q/A,但答案需要一个真实的设备!

2 个答案:

答案 0 :(得分:21)

我遇到此问题的主要原因是我使用Xcode 5构建我的应用程序并使用Xcode 6

打开它

解决方案:

为Retina HD 5.5和4.7添加启动图像:

enter image description here

现在,您无需使用真实设备即可在模拟器上检测到iPhone 6 / Plus:

#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)

答案 1 :(得分:2)

如果您需要在横向上检测iPhone 6 / 6Plus,请使用此功能。

 #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)