如何检查是否支持Haptic Engine(UIFeedbackGenerator) [英] How to check if Haptic Engine (UIFeedbackGenerator) is supported

查看:471
本文介绍了如何检查是否支持Haptic Engine(UIFeedbackGenerator)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们如何检查当前设备上是否有新的iOS 10 API UIFeebackGenerator 。还有一些我们需要检查的事情:

I am wondering how we could check if the new iOS 10 API UIFeebackGenerator is available on the current device. There are some more things we would need to check:


  1. 设备需要运行iOS 10.0或更高版本

  2. 设备需要是iPhone 7或更高版本

  3. 需要在设置中打开触觉引擎

前两个检查可以使用 #available(iOS 10,*)语句和(hacky)设备检测来实现,但后者一个似乎不可检查。

The first two checks can be achieved using #available(iOS 10, *) statement and a (hacky) device-detection, but the latter one doesn't seem to be checkable.

有人知道这方面的解决方案吗?或许我们需要为此提交Apple Radar。谢谢!

Does someone know a solution for this? Or maybe we need to file an Apple Radar for this one. Thanks!

推荐答案

基于 Apple的 UIFeedbackGenerator 文档,听起来就像iOS那样。

Based on Apple's UIFeedbackGenerator documentation, sounds like iOS does that for you.


请注意,调用这些方法不会直接播放触觉。
相反,它会通知系统事件。 系统然后
决定是否根据设备

应用程序的状态,剩余电池电量以及其他
因素播放触觉。

Note that calling these methods does not play haptics directly. Instead, it informs the system of the event. The system then determines whether to play the haptics based on the device, the application’s state, the amount of battery power remaining, and other factors.

例如,目前仅播放触觉反馈:

For example, haptic feedback is currently played only:

在支持Taptic Engine的设备上(iPhone 7和iPhone 7
Plus)。

On a device with a supported Taptic Engine (iPhone 7 and iPhone 7 Plus).

当应用程序在前台运行时。

When the app is running in the foreground.

当系统触觉设置已启用。

When the System Haptics setting is enabled.

即使您不需要担心检查设备是否可以执行触觉反馈,您仍然需要确保它只能在iOS 10或更高版本中调用,所以你可以用这个来实现:

Even if you don't need to worry about check whether the device can do haptic feedback, you still need to ensure it's called only with iOS 10 or greater, so you could accomplish that with this:

    if #available(iOS 10,*) {
        // your haptic feedback method
    }

这是< a href =https://stackoverflow.com/a/40228668/4475605>各种触觉反馈的快速摘要iOS 10中提供的选项。

这篇关于如何检查是否支持Haptic Engine(UIFeedbackGenerator)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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