Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIFeedback Haptic Engine called more times than was activated

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:]
like image 727
fatihyildizhan Avatar asked Oct 26 '16 23:10

fatihyildizhan


People also ask

How do you generate haptic feedback?

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.

What is Uiimpactfeedbackgenerator?

A concrete feedback generator subclass that creates haptics to simulate physical impacts. iOS 10.0+ iPadOS 10.0+ Mac Catalyst 13.1+


1 Answers

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()
}
like image 180
Tal Zion Avatar answered Sep 21 '22 06:09

Tal Zion