检查设备是否支持模糊 [英] Check if device supports blur
问题描述
我的应用使用 UIBlurEffect
,但是较旧的设备(特别是iPad 2和3,支持iOS 8)没有模糊支持。
My app uses UIBlurEffect
, however older devices (specifically iPads 2 and 3, that support iOS 8) don't have blur support.
我想检查用户的设备是否支持模糊。我该怎么做?
I'd like to check if the user's device has blur support or not. How do I do it?
推荐答案
UIDevice
有一个内部方法 [UIDevice _graphicsQuality]
这似乎很有希望,但当然你的应用程序将被Apple拒绝。让我们创建自己的方法:
UIDevice
has an internal method [UIDevice _graphicsQuality]
that seems promising, but of course your app will be rejected by Apple. Let's create our own method:
首先,我们需要知道我们正在处理的确切设备类型:
First of all, we need to know the exact device type we're working on:
#import <sys/utsname.h>
NSString* deviceName()
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
这应该返回 iPad2,1 $ c例如,$ c>适用于iPad 2。以下是iDevice模型的更新列表: https://theiphonewiki.com/wiki/Models
This should return iPad2,1
for iPad 2, for example. Here's an updated list of iDevice models: https://theiphonewiki.com/wiki/Models
因此,让我们将设备模型分为两组:图形质量差(因此不支持模糊),以及具有出色图形质量的设备模型。根据我的调查,这些是Apple认为差图形的设备(这些可能会在未来发生变化):
So, let's classify our device models in two groups: those that have poor graphics quality (and thus don't support blur), and those with great graphics quality. According to my investigation, these are the devices that Apple considers with "poor" graphics (these may change in the future):
iPad iPad1 ,1 iPhone1,1 iPhone1,2 iPhone2,1 iPhone3,1 iPhone3,2
iPhone3,3 iPod1,1 iPod2,1 iPod2,2 iPod3,1 iPod4,1 iPad2,1 iPad2,2
iPad2 ,3 iPad2,4 iPad3,1 iPad3,2 iPad3,3
iPad iPad1,1 iPhone1,1 iPhone1,2 iPhone2,1 iPhone3,1 iPhone3,2 iPhone3,3 iPod1,1 iPod2,1 iPod2,2 iPod3,1 iPod4,1 iPad2,1 iPad2,2 iPad2,3 iPad2,4 iPad3,1 iPad3,2 iPad3,3
所以我们编写以下代码:
So we write the following code:
NSSet *graphicsQuality = [NSSet setWithObjects:@"iPad",
@"iPad1,1",
@"iPhone1,1",
@"iPhone1,2",
@"iPhone2,1",
@"iPhone3,1",
@"iPhone3,2",
@"iPhone3,3",
@"iPod1,1",
@"iPod2,1",
@"iPod2,2",
@"iPod3,1",
@"iPod4,1",
@"iPad2,1",
@"iPad2,2",
@"iPad2,3",
@"iPad2,4",
@"iPad3,1",
@"iPad3,2",
@"iPad3,3",
nil];
if ([graphicsQuality containsObject:deviceName()]) {
// Device with poor graphics, blur not supported
} else {
// Blur supported
}
请注意,即使设备可能支持模糊,用户也可能已禁用设置中的高级视觉效果,辅助功能。
Be careful because even though the device may support blur, the user may have disabled advanced visual effects from Settings, Accessibility.
替代方法
https://gist.github.com/conradev/8655650
这篇关于检查设备是否支持模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!