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:
- The device needs to run iOS 10.0 or later
- The device needs to be an iPhone 7 or later
- The Haptic Engine needs to be turned on in the Settings
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.
Does someone know a solution for this? Or maybe we need to file an Apple Radar for this one. Thanks!
You know your device support Haptic vibration effect or not with below code,
These methods seem to return:
0 = Taptic not available
1 = First generation (tested on an iPhone 6s) ... which does NOT support UINotificationFeedbackGenerator, etc.
it returns 2 for devices with haptic feedback - iPhone 7/7+ or higher so, you can easily use this to generate Haptic feedback
This will work for iPhone 7 and Above.
There's some undocumented "private thing":
it returns 2 for devices with haptic feedback - iPhone 7/7+ so you can easily use this to generate Haptic feedback:
returns 1 for iPhone 6S, here's a fallback to generate taptic:
and returns 0 for iPhone 6 or older devices. Since it's kind of undocumented thing it might block you during the review stage, although I was able to pass review and submit the app with such check.
More details: http://www.mikitamanko.com/blog/2017/01/29/haptic-feedback-with-uifeedbackgenerator/
Based on Apple's
UIFeedbackGenerator
documentation, sounds like iOS does that for you.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:
Here's a quick summary of the various haptic feedback options available in iOS 10.