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