问题
I have iphone app in which I was till now successfully checking is iphone 5 with following code (in my Prefix.pch file):
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
Now when I run on my iPhone 5, I get this height in log: 480 ([[UIScreen mainScreen] bounds].size.height)
I've updated my iPhone on iOS 7. Is there some other way to check if is iPhone 5 (or height of screen)?
UPDATE: I have on my MAC OSX 10.8.5
UPDATE 2: I've figured it out that there is some bug in that project because when I create new project all examples code work.
回答1:
I just tested this code and it works checking for iPhone 5 & 4 and iOS 7 Just a bunch of pesky nested If statements!
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960){
NSLog(@"iphone 4, 4s retina resolution");
//CODE IF IPHONE 4
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
//Code if iPhone 4 or 4s and iOS 7
NSLog(@"iPhone 4 iOS 7");
}
}
if(result.height == 1136){
NSLog(@"iphone 5 resolution");
//CODE IF iPHONE 5
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
//Code if iPhone 5 or 5s and iOS 7
NSLog(@"iPhone 5 iOS 7");
}
}
}
}
回答2:
Use this :
bool isFourInches = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
isFourInches
will be "YES" if the device has a four inches display, it could be an iPhone 5, 5s or 5c...
回答3:
Try the condition below ...
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
NSLog(@"iOS 7");
}
来源:https://stackoverflow.com/questions/18933741/how-to-check-if-is-iphone-5-in-ios-7