I am using the UIFeedback Haptic Engine
with swift 2.3 like:
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.Warning)
and
let generator = UIImpactFeedbackGenerator(style: .Heavy)
generator.impactOccurred()
Today I got a new kind of error like this, and couldn't find the problem. Do you have any idea?
UIFeedbackHapticEngine _deactivate] called more times than the feedback engine was activated
Details:
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1863e41c0 __exceptionPreprocess
1 libobjc.A.dylib 0x184e1c55c objc_exception_throw
2 CoreFoundation 0x1863e4094 +[NSException raise:format:]
3 Foundation 0x186e6e82c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 UIKit 0x18cc43fb8 -[_UIFeedbackEngine _deactivate]
5 UIKit 0x18cad781c -[UIFeedbackGenerator __deactivateWithStyle:]
To generate haptic feedback, the view controller calls selectionChanged() on the UISelectionFeedbackGenerator instance. That's it. As the name suggests, this type of haptic feedback should be used to communicate that a change in selection took place.
A concrete feedback generator subclass that creates haptics to simulate physical impacts. iOS 10.0+ iPadOS 10.0+ Mac Catalyst 13.1+
Calling generator.impactOccurred()
will crash on iOS 11.*. You need to call that on the main thread async
.
let generator = UIImpactFeedbackGenerator(style: style)
generator.prepare()
DispatchQueue.main.async {
generator.impactOccurred()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With