回答
有一个内部方法[UIDevice _graphicsQuality]
看起来很有前途,但当然你的应用程序将被苹果拒绝。让我们来创建我们自己的方法:
首先,我们需要知道我们正在处理的确切设备类型:
#import <sys/utsname.h>
NSString* deviceName()
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
这应该为iPad 2返回iPad2,1
,例如。下面是iDevice机型的更新列表:https://theiphonewiki.com/wiki/Models
因此,让我们将设备模型分为两组:那些图形质量较差(因此不支持模糊)的设备模型以及具有出色图形质量的设备模型。根据我的调查,这些是苹果公司认为的“差”图形设备(这些可能会在未来发生变化):
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
所以我们写下面的代码:
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
}
要小心,因为即使该设备可能支持模糊,用户可能已禁用了设置,辅助功能中的高级视觉效果。
替代方法
这里有几个方法可以做到这一点:
if objc_getClass("UIBlurEffect") != nil {
// UIBlurEffect exists
} else {
// UIBlurEffect doesn't exist
}
或者能够访问blurEffect类
if let blurEffect: AnyClass = NSClassFromString("UIBlurEffect") {
// UIBlurEffect exists
} else {
// UIBlurEffect doesn't exist
}
这事实上是在这里重复的问题,虽然标题可能不使它容易找到:How do I do weak linking in Swift?
- 编辑 -
误解了这个问题。那里看来是没办法短检查设备名称的发现了这一点:
Detect if device properly displays UIVisualEffectView?
我将依靠任何苹果的后备实现。看起来他们仍然应用色调,以便在大多数情况下可能很好。如果在不应用模糊时确实必须更改外观,我认为设备名称并不可怕,因为它们特别列出了哪些设备不支持模糊。
非常感谢丹尼尔做马丁的伟大答案。 我已经做了的UIDevice类,它结合了以下检查的模糊效果的可用性:
的iOS版本
设备类型(感谢丹尼尔·马丁)
私人的UIDevice方法_graphicsQuality当为模拟器建造时。 (因为设备类型检查在模拟器不工作这样做 - 将建设ARM体系结构时,可以编出)
“透明度降低的辅助功能设置
我做了一个含有类要点: https://gist.github.com/mortenbekditlevsen/5a0ee16b73a084ba404d
而关于这个问题作为一个整体小新手必看:
注意:使用该要点时,不要忘记订阅
UIAccessibilityReduceTransparencyStatusDidChangeNotification通知,以便在辅助功能设置更改时刷新UI。
我希望有人认为这有用。 :-)
这是丹尼尔马丁的答案的Swift版本。一些代码改编自here:
func isBlurSupported() -> Bool {
var supported = Set<String>()
supported.insert("iPad")
supported.insert("iPad1,1")
supported.insert("iPhone1,1")
supported.insert("iPhone1,2")
supported.insert("iPhone2,1")
supported.insert("iPhone3,1")
supported.insert("iPhone3,2")
supported.insert("iPhone3,3")
supported.insert("iPod1,1")
supported.insert("iPod2,1")
supported.insert("iPod2,2")
supported.insert("iPod3,1")
supported.insert("iPod4,1")
supported.insert("iPad2,1")
supported.insert("iPad2,2")
supported.insert("iPad2,3")
supported.insert("iPad2,4")
supported.insert("iPad3,1")
supported.insert("iPad3,2")
supported.insert("iPad3,3")
return !supported.contains(hardwareString())
}
func hardwareString() -> String {
var name: [Int32] = [CTL_HW, HW_MACHINE]
var size: Int = 2
sysctl(&name, 2, nil, &size, &name, 0)
var hw_machine = [CChar](count: Int(size), repeatedValue: 0)
sysctl(&name, 2, &hw_machine, &size, &name, 0)
let hardware: String = String.fromCString(hw_machine)!
return hardware
}
- 1. 如何检测iOS设备是否支持模糊效果?
- 2. 如何检查Android设备GPS模块是否有AGPS支持
- 3. 检测设备是否支持jQuery Mobile
- 4. 检测设备是否支持电话?
- 5. 检查设备是否支持以JPEG和PNG格式保存
- 6. 如何检查iOS 11安装的设备是否支持ARKit?
- 7. As3 AIR如何检查设备是否支持tel?
- 8. 检查iOS9设备是否支持3D触摸并启用
- 9. 如何检查Android设备是否支持gps?
- 10. 检查是否支持ALPN
- 11. IOS CoreImage Framework是否支持模糊检测
- 12. 如何检测浏览器是否支持CSS3模糊?
- 13. 检查对所有设备的支持
- 14. Datapower设备XI52是否支持ActiveMQ?
- 15. 检查浏览器是否支持移动设备的SVG,最好是Android
- 16. 如何检测设备是否支持FaceID?
- 17. 检测移动设备是否支持J2ME WMA
- 18. 检测浏览器/设备是否支持双击事件
- 19. javascript检测浏览器/设备是否支持屏幕旋转
- 20. 如何可靠地检测绑定设备是否支持GATT?
- 21. 如何检测iOS设备是否支持推送通知?
- 22. BigVideo.js - 检查浏览器是否支持,背景图片备用
- 23. 如何检查Android备份服务是否受支持?
- 24. 如何检查ios设备中的Facetime支持(硬件检查)
- 25. 如何知道移动设备或设备是否支持USB配件模式?
- 26. OpenGLES2.0 android设备是否保证支持模板缓冲区?
- 27. 如何检查特定语言是由设备支持的android
- 28. 以编程方式查找设备是否支持GPS?
- 29. GLSL:检查是否支持扩展
- 30. 检查setOrientation()是否受支持?
使用模拟器时,'systemInfo.machine'属性是x86_64(在我的Mac上); – Tjalsma