在我的应用程序中,我正在从网络(准确地说是从我的服务器)下载一些图像,为了节省一些带宽,尤其是手机上的内存,我以两种分辨率提供它们:480x320 用于“旧”iPhone 系列和960x640 适用于配备 Retina 显示屏的 iPhone 4。现在,我需要能够在应用程序在支持视网膜屏幕的设备上运行时从应用程序内部进行检测。我怎么能那样做?
我一直在考虑使用下面的代码片段,它会返回一个特定的设备标识符,例如。“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];
有没有更好的解决方案(也许很明显,但我错过了)?