How to check if Haptic Engine (UIFeedbackGenerator) is supported

There's some undocumented "private thing":

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

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

let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.prepare()
generator.impactOccurred()

returns 1 for iPhone 6S, here's a fallback to generate taptic:

import AudioToolbox

AudioServicesPlaySystemSound(1519) // Actuate `Peek` feedback (weak boom)
AudioServicesPlaySystemSound(1520) // Actuate `Pop` feedback (strong boom)
AudioServicesPlaySystemSound(1521) // Actuate `Nope` feedback (series of three weak booms)

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/


Starting from iOS 13 you can check it in a very straightforward way. According to documentation page, all you have to do is:

import CoreHaptics

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

Documentation: Preparing Your App to Play Haptics


Based on Apple's UIFeedbackGenerator documentation, sounds like iOS does that for you.

Note that calling these methods does not play haptics directly. Instead, it informs the system of the event. The system then determines whether to play the haptics based on the device, the application’s state, the amount of battery power remaining, and other factors.

For example, haptic feedback is currently played only:

On a device with a supported Taptic Engine (iPhone 7 and iPhone 7 Plus).

When the app is running in the foreground.

When the System Haptics setting is enabled.

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:

    if #available(iOS 10,*) {
        // your haptic feedback method
    }

Here's a quick summary of the various haptic feedback options available in iOS 10.


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