iOS SDK是否提供了一种简单的方法来检查currentDevice是否具有高分辨率显示器(视网膜)?
我发现现在最好的方法是:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {
// RETINA DISPLAY
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我正在从网上下载一些图像(从我的服务器到精确),为了节省一些带宽,尤其是手机上的内存,我提供两种分辨率:480x320用于"旧"iPhone系列和带有视网膜显示屏的iPhone 4为960x640.现在,我需要能够在应用程序中检测它何时在支持视网膜屏幕的设备上运行.我怎么能这样做?
我一直在考虑使用下面的代码片段,它会返回一个特定的设备标识符,例如."iPhone3",然后我将限制检测到iPhone4,并需要为具有视网膜显示器的任何后续设备更新该代码.
size_t size;
// Set 'oldp' parameter to NULL to get the size of the data
// returned so we can allocate appropriate amount of space
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
// Allocate the space to store name
char *name = malloc(size);
// Get the platform name
sysctlbyname("hw.machine", name, &size, NULL, 0);
// Place name into a string
NSString *machine = [NSString stringWithCString:name];
Run Code Online (Sandbox Code Playgroud)
有没有更好的选择(也许这是非常明显但我错过了它)?