在我的应用程序中,我从网上下载一些图像(从我的服务器到精确),为了节省一些带宽,特别是手机内存,我提供了两个分辨率:“旧”iPhone系列为480x320,视网膜显示屏为iPhone 4的960x640。现在,我需要能够在应用程序内运行支持视网膜屏幕的设备时进行检测。我怎么能这样做?在iPhone SDK中检测视网膜屏幕/ 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];
有没有更好的饮料(可能它很明显,但我错过了)?
这是做它的正确途径。 – Elfred 2010-07-17 19:08:02
是的,使用这个,千万不要试图查询你正在运行的设备,它只会以痛苦结束。 – 2010-07-17 23:25:09
这是正确的方法,因为您不想为iPhone 4编写条件代码,而是为具有不同比例/分辨率的显示器编写条件代码。谁知道iPod什么时候能够获得视网膜治疗。 – FelixLam 2010-07-18 09:38:02