我使用的是带有UIFeedback Haptic Engine的Wavid2.3,如:
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.Warning)和
let generator = UIImpactFeedbackGenerator(style: .Heavy)
generator.impactOccurred()今天我遇到了这样一个新的错误,却找不到问题。你有什么想法吗?
UIFeedbackHapticEngine _deactivate] called more times than the feedback engine was activated详细信息:
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:]发布于 2016-10-27 09:53:17
UIImpactFeedbackGenerator不是线程安全的,所以要确保同步调用generator.impactOccurred(),而不是在dispatch_async或其他异步线程中调用。
发布于 2018-08-15 14:57:43
调用generator.impactOccurred()将在iOS 11.*上崩溃。您需要在主线程async上调用它。
let generator = UIImpactFeedbackGenerator(style: style)
generator.prepare()
DispatchQueue.main.async {
generator.impactOccurred()
}发布于 2020-10-06 15:49:10
为了完成已经给出的答案:您想要做的要么是拥有一个OperationQueue或一个DispatchQueue,它总是用于调用FeedbackGenerator的函数。请记住,对于用例,您可能需要释放生成器,但最起码的例子是:
class HapticsService {
private let hapticsQueue = DispatchQueue(label: "dev.alecrim.hapticQueue", qos: .userInteractive)
typealias FeedbackType = UINotificationFeedbackGenerator.FeedbackType
private let feedbackGeneator = UINotificationFeedbackGenerator()
private let selectionGenerator = UISelectionFeedbackGenerator()
func prepareForHaptic() {
hapticsQueue.async {
self.feedbackGeneator.prepare()
self.selectionGenerator.prepare()
}
}
func performHaptic(feedback: FeedbackType) {
hapticsQueue.async {
self.feedbackGeneator.notificationOccurred(feedback)
}
}
func performSelectionHaptic() {
hapticsQueue.async {
self.selectionGenerator.selectionChanged()
}
}
}这在很大程度上解决了我们生产中的相关问题。
https://stackoverflow.com/questions/40273911
复制相似问题