相关疑难解决方法(0)

在iPhone SDK中检测视网膜屏幕/ iPhone 4

在我的应用程序中,我正在从网上下载一些图像(从我的服务器到精确),为了节省一些带宽,尤其是手机上的内存,我提供两种分辨率: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)

有没有更好的选择(也许这是非常明显但我错过了它)?

iphone cocoa-touch iphone-4

23
推荐指数
4
解决办法
2万
查看次数

标签 统计

cocoa-touch ×1

iphone ×1

iphone-4 ×1