我在iOS 13中看到与观察AVPlayer.timeControlStatus
相关的奇怪崩溃,这在iOS 12中没有发生。
这是设置观察者的代码:
// stored in View Controller
private var playerStateObservation: NSKeyValueObservation?
@objc var player : AVPlayer?
// setting KVO after initialising AVPLayer
playerStateObservation = observe(\.player?.timeControlStatus) { [weak self] (object, change) in
let playing = self?.player?.timeControlStatus == .playing
self?.showPlayIcon(playing)
}
这里是停止观察的功能。在ViewController deinit
中调用。
func cleanUpObserver() {
playerStateObservation?.invalidate()
playerStateObservation = nil
}
在以下情况下发生崩溃:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x2b1bc593c)
这里是崩溃的调用堆栈。
看起来AVPlayer正在尝试向应该已经无效并从内存中释放的观察者发送通知。有人遇到过类似的问题吗?