How to Check If Haptic Engine (Uifeedbackgenerator) Is Supported

How to check if Haptic Engine (UIFeedbackGenerator) is supported

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.

iOS Haptic Feedback not firing

So, took a bit of digging but appears the issue was that I was testing on a iPhone 6 which does not support the UINotificationFeedbackGenerator. I figured since they provide the haptic touches on it, and no errors were being thrown all was right in the world.

So, here is what I wound up doing:

let modelName = UIDevice.modelName
if audioModels.contains(modelName) {
AudioServicesPlaySystemSound(1519)
} else {
UINotificationFeedbackGenerator().notificationOccurred(.success)
}

The UIDevice.modelName is just helper function I found on the internet (prob. Stack) that gets the device name. I then compare that name to a little array I setup - audioModels - of devices that need to have the audio played instead of using the NotificationFeedbackGenerator. Not sure if there is a better more intuitive way to check for the functionality per device (let me know if there is) but this is working for me.

Thanks again for looking into the issue.

Haptic engine iPhone stronger impact

func generateVibration() {

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

The more times you call generator.impactOccured(), the stronger the impact will be.



Related Topics



Leave a reply



Submit