当我从屏幕返回并再次进入屏幕时,即使我删除了目标nextTrackCommand
,也会多次调用目标viewWillDisappear
。我做错了什么?
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.beginReceivingRemoteControlEvents()
MPRemoteCommandCenter.shared().nextTrackCommand.addTarget { [unowned self] (_) -> MPRemoteCommandHandlerStatus in
print("go to next track")
return .success
}
}
override func viewWillDisappear(_ animated: Bool) {
MPRemoteCommandCenter.shared().nextTrackCommand.removeTarget(self)
}