I'm working with some UIGestures (in particular a force touch). I have all of that working, the additional UI updates/animations all working per the forced touch. However, I would like to add in the haptic touch feedback on the hard press. To my dismay, this snippet of code is not working. The function is called, interface updated, but no haptic feedback. Is there something I'm missing here? Permissions, capability, etc.?
@objc func forceTouchHandler(_ sender: ForceTouchGestureRecognizer) {
print("force touch")
UINotificationFeedbackGenerator().notificationOccurred(.success)
self.updateInterface()
}
Thanks in advance for any feedback.
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.