Мой код отлично работает на iOS 12 и ниже:
fileprivate func setupRemoteControl() {
UIApplication.shared.beginReceivingRemoteControlEvents()
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.addTarget { (_) -> MPRemoteCommandHandlerStatus in
self.player.play()
self.playPause.setImage(#imageLiteral(resourceName: "PausePlayer"), for: .normal)
self.miniPlayPauseButton.setImage(#imageLiteral(resourceName: "PausePlayerMini"), for: .normal)
self.setupElapsedTime()
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 1
return .success
}
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.addTarget { (_) -> MPRemoteCommandHandlerStatus in
self.player.pause()
self.playPause.setImage(#imageLiteral(resourceName: "PlayPlayer"), for: .normal)
self.miniPlayPauseButton.setImage(#imageLiteral(resourceName: "PlayPlayerMini"), for: .normal)
self.setupElapsedTime()
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 0
return .success
}
commandCenter.togglePlayPauseCommand.isEnabled = true
commandCenter.togglePlayPauseCommand.addTarget { (_) -> MPRemoteCommandHandlerStatus in
self.handlePlayPause()
return .success
}
commandCenter.skipForwardCommand.addTarget(self, action: #selector(handleSkipForward))
commandCenter.skipBackwardCommand.addTarget(self, action: #selector(handleSkipBackward))
}
@objc fileprivate func handleSkipForward() {
print("Seek 15 sec forward")
let fifteenSeconds = CMTimeMakeWithSeconds(15, Int32(NSEC_PER_SEC))
let seekTime = CMTimeAdd(player.currentTime(), fifteenSeconds)
let elapsedTime = CMTimeGetSeconds(seekTime)
MPNowPlayingInfoCenter.default().nowPlayingInfo![MPNowPlayingInfoPropertyElapsedPlaybackTime] = elapsedTime
player.seek(to: seekTime)
}
@objc fileprivate func handleSkipBackward() {
print("Seek 15 sec backward")
let fifteenSeconds = CMTimeMakeWithSeconds(-15, Int32(NSEC_PER_SEC))
let seekTime = CMTimeAdd(player.currentTime(), fifteenSeconds)
let elapsedTime = CMTimeGetSeconds(seekTime)
MPNowPlayingInfoCenter.default().nowPlayingInfo![MPNowPlayingInfoPropertyElapsedPlaybackTime] = elapsedTime
player.seek(to: seekTime)
}
Но когда я пытаюсь запустить симулятор iOS 13, приложение вылетает с ошибкой в файле AppDelegate:
"Поток 1: Исключение:" Неподдерживаемая подпись метода действия. Необходимо вернуть MPRemoteCommandHandlerStatus или взять обработчик завершения в качестве второго аргумента. "
В чем проблема?