How to check if Haptic Engine (UIFeedbackGenerator) is supported

后端 未结 6 1007
星月不相逢
星月不相逢 2020-12-09 03:22

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

6条回答
  •  轮回少年
    2020-12-09 03:53

    on iOS 13 you can check it in a very straightforward fashion. Following this documentation page, all you have to do is:

    iOS 13, Swift 5

    var supportsHaptics: Bool = false
    ...
    // Check if the device supports haptics.
    let hapticCapability = CHHapticEngine.capabilitiesForHardware()
    supportsHaptics = hapticCapability.supportsHaptics
    

提交回复
热议问题