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