How to check if Haptic Engine (UIFeedbackGenerator) is supported

后端 未结 6 1004
星月不相逢
星月不相逢 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:48

    I made an extension to UIDevice without using the private API

    extension UIDevice {
    
    static var isHapticsSupported : Bool {
        let feedback = UIImpactFeedbackGenerator(style: .heavy)
        feedback.prepare()
        return feedback.description.hasSuffix("Heavy>")
    }
    

    } and you use it like this :

    UIDevice.isHapticsSupported 
    

    returns true or false

提交回复
热议问题