所以我所做的是:首先我按以下顺序使用方法:
if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus
} else if (screenBounds.size.height == 568) {
//4 inch code
} else {
//3.5 inch code
}
if else
然后我想既然计算机一旦找到一个真实的语句就会停止运行该语句,我只是将顺序重新排列为以下内容:
if (screenBounds.size.height == 480) {
//3.5 inch code
} else if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus
} else if (screenBounds.size.height == 568) {
//4 inch code
}
这支持带有 iOS 7 或更低版本的 iPhone 4S。在 iPhone 5 / 5S 上它仍然会崩溃。这就是为什么我最终将其更改为以下内容:
if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) {
//checks if device is running on iOS 8, skips if not
NSLog(@"iOS 8 device");
if (screenBounds.size.height == 480) {
//3.5 inch code
NSLog(@"iPhone 4S detected");
} else if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus
NSLog(@"iPhone 6 plus detected");
} else if (screenBounds.size.height == 568) {
//4 inch code
NSLog(@"iPhone 5 / 5S / 6 detected");
}
} else if (screenBounds.size.height == 480) {
//checks if device is tunning iOS 7 or below if not iOS 8
NSLog(@"iOS 7- device");
NSLog(@"iPhone 4S detected");
//3.5 inch code
} else if (screenBounds.size.height == 568) {
NSLog(@"iOS 7- device");
NSLog(@"iPhone 5 / 5S / 6 detected");
//4 inch code
}
它现在应该可以在任何 iOS 7 和 iOS 8 设备上完全运行!