在iPhone SDK中检测视网膜屏/ iPhone 4 [英] Detect retina screen/iPhone 4 in iPhone SDK

查看:124
本文介绍了在iPhone SDK中检测视网膜屏/ iPhone 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我从网上下载一些图像(从我的服务器是精确的),为了节省一些带宽,特别是手机内存,我提供他们在两个分辨率:480x320为老iPhone系列和960x640为iPhone 4与视网膜显示。现在我需要能够在应用程序内检测它在支持视网膜屏幕的设备上运行。

In my application I am downloading some images from the web (from my server to be precise), in order to save some bandwith and especially memory on the phone, I provide them in two resolutions: 480x320 for the "old" iPhone series and in 960x640 for the iPhone 4 with the retina display. Now I need to be able to detect from within the app when it is running on a device that supports the retina screen. How could I do that?

我一直在考虑使用下面的代码片段,它会返回一个特定的设备标识符,例如eg。 iPhone3,然后我会限制检测到iPhone4,并需要更新该代码为任何后续的设备与视网膜显示。

I have been thinking about using the code snippet below which would return me a specific device identifier such as eg. "iPhone3", yet then I would be limiting the detection to the iPhone4 and would need to update that code for any subsequent device with a retina display.

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];

有更好的感觉(也许很明显,但我错过了)?

Is there any better soution (maybe it is very obvious but I missed it)?

推荐答案

刚刚在官方的苹果开发者论坛上做了一些阅读,问题已经讨论了很长时间。对我来说最好的方法似乎是使用 UIScreen scale 属性。虽然它只在 iOS 4 中可用,后来它会告诉你你需要知道的一切,并且很可能在将来发挥更重要的作用(已经注意到iPad的屏幕分辨率为1024x768,正好是32/15 * 480x320?)。

Just did some reading on the official Apple Developers Forums and the issues has been discussed in length there. The best way to me seems to be the use of the scale property of UIScreen. Although it is only available in iOS 4 and later, it will tell you everything you need to know and will most likely play an even more important role in the future (already noticed that the iPad's screen resolution of 1024x768 is exactly 32/15 * 480x320?).

UIScreen.mainScreen.scale

如果您还有其他想法,可以发布:)

If you have yet another idea feel free to post it :)

这篇关于在iPhone SDK中检测视网膜屏/ iPhone 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆