iOS和CoreHaptics-Xcode说完成了模拟器设备,也没有我的iPhone 7支持触觉

问题描述 投票:-1回答:3

我正在使用Xcode 11.3.1中的CoreHaptics,并与Paul Hudson(https://www.hackingwithswift.com/example-code/core-haptics/how-to-play-custom-vibrations-using-core-haptics)的出色文章合作。但是,在他的示例代码中,检查触觉功能的行始终返回false。即下一行

 guard CHHapticEngine.capabilitiesForHardware().supportsHaptics 

总是返回false。我已经尝试过使用实际的iPhone7 plus以及Xcode中所有可用的iPhone模拟器。当我尝试删除该行时,触觉引擎的创建确实失败了。

显然,这些设备支持触觉功能(至少我的手机当然支持);我想念什么?

ios swift xcode 3dtouch
3个回答
0
投票

相信运行时。如果

CHHapticEngine.capabilitiesForHardware().supportsHaptics

返回false,它是false。

至少我的手机当然可以

相信运行时!您的手机肯定没有。 iPhone 7没有Taptic Engine;它是在iPhone 8中引入的。请勿与现实打架。运行时告诉您真相。


0
投票

Bhargav,我很好奇您为什么删除我的信息。


-1
投票

CoreHaptics SKD仅支持iOS 13.0+设备。

并非所有设备都支持CoreHaptics,这就是为什么在尝试启动任何触觉反馈之前应始终检查支持的硬件的原因。您可以像这样检测触觉可用性:

if CHHapticEngine.capabilitiesForHardware().supportsHaptics {
    // your haptics code here
}

https://www.hackingwithswift.com/example-code/core-haptics/how-to-detect-whether-haptic-event-playback-is-supported

https://developer.apple.com/documentation/corehaptics

© www.soinside.com 2019 - 2024. All rights reserved.