Mar*_*tos 27
检查带相机的iPad.
BOOL isIPad2 = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
[UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]);
Run Code Online (Sandbox Code Playgroud)
请注意,通常更好的方法是检测特定功能,而不是根据模型/版本检测进行全面假设.例如,如果您需要相机,请明确测试相机; 如果你需要根据可用的RAM量来调整UI质量,请测试物理RAM ; 另外请注意我写的评论强调了使用模型检测的危险.
Tom*_*ana 13
model除了出于信息目的或诊断输出而显示它之外,切勿使用该属性.它不能保证保留,如果你依赖它,你会不必要地切断新设备.
许多iPhone应用程序无法在iPad的兼容模式下使用,因为他们检查了model属性,如果不是iPhone/iPod,他们没有做任何事情.
要获得精确的模型字符串,例如"iPad2,2",您可以使用类似的东西.
#import "YourDeviceDetectionClass.h"
#include <sys/utsname.h>
@implementation YourDeviceDetectionClass
+(NSString*)modelAsString
{
struct utsname platform;
int rc = uname(&platform);
if(rc == -1)
{
// Error...
return nil;
}
else
{
// Convert C-string to NSString
return [NSString stringWithCString:platform.machine encoding:NSUTF8StringEncoding];
}
}
@end
Run Code Online (Sandbox Code Playgroud)
UIScreen + Retina.h #import
@interface UIScreen(Retina)
// Returns YES if this is a Retina display.
- (BOOL)isRetina;
@end
Run Code Online (Sandbox Code Playgroud)
UIScreen + Retina.m
#import "UIScreen+Retina.h"
@implementation UIScreen(Retina)
- (BOOL)isRetina {
return [self respondsToSelector:@selector(displayLinkWithTarget:selector:)] && (self.scale == 2.0);
}
@end
Run Code Online (Sandbox Code Playgroud)
用法
#import "UIScreen+Retina.h"
Run Code Online (Sandbox Code Playgroud)
//http://stackoverflow.com/questions/3294100/how-to-differentiate-between-iphone4-and-iphone-3
if ([[UIScreen mainScreen] isRetina]) {
// Retina display
}
Run Code Online (Sandbox Code Playgroud)
IPAD/IPHONE HIGH/LOW RES
#import "UIScreen+Retina.h"
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
//IPAD
if ([[UIScreen mainScreen] isRetina]) {
// IPAD 3 - Retina display
bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPAD_HIGHRES;
}else{
//iPAD 1/2
bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPAD_LOWRES; }
}else{
//IPHONE
if ([[UIScreen mainScreen] isRetina]) {
// IPHONE 4/4s/5 - Retina display
bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPHONE_HIGHRES;
}else{
//IPHONE (3.x)
bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPHONE_LOWRES;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12164 次 |
| 最近记录: |