这是我在代码中所做的:
commandCenter.pauseCommand.addTarget(self, action: #selector(pause))
@objc private func pause() {
player?.pause()
playButton.setImage(UIImage(named: "icon-play")?.alwaysTemplate, for: .normal)
delegate?.playerViewDidPause()
}
这是运行应用程序时出现的错误:
***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'不支持的操作方法签名。必须返回MPRemoteCommandHandlerStatus或将完成处理程序作为第二个参数。'
您应该这样更改方法:
@objc private func pause() -> MPRemoteCommandHandlerStatus {
player?.pause()
playButton.setImage(UIImage(named: "icon-play")?.alwaysTemplate, for: .normal)
delegate?.playerViewDidPause()
return .success
}
一切都会像咒语一样运作😀