How to check if Haptic Engine (UIFeedbackGenerator) is supported

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

    You know your device support Haptic vibration effect or not with below code,

    UIDevice.currentDevice().valueForKey("_feedbackSupportLevel");
    

    These methods seem to return:

    • 0 = Taptic not available

    • 1 = First generation (tested on an iPhone 6s) ... which does NOT support UINotificationFeedbackGenerator, etc.

    • 2= Second generation (tested on an iPhone 7) ... which does support it.

    it returns 2 for devices with haptic feedback - iPhone 7/7+ or higher so, you can easily use this to generate Haptic feedback

提交回复
热议问题