Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must return MPRemoteCommandHandlerStatus or take a completion handler as the second argument

This is what I do in my code:

commandCenter.pauseCommand.addTarget(self, action: #selector(pause))

@objc private func pause() {
    player?.pause()
    playButton.setImage(UIImage(named: "icon-play")?.alwaysTemplate, for: .normal)
    delegate?.playerViewDidPause()
}

And this is error I get when I run the app:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported action method signature. Must return MPRemoteCommandHandlerStatus or take a completion handler as the second argument.'

like image 779
Bartłomiej Semańczyk Avatar asked Feb 04 '20 10:02

Bartłomiej Semańczyk


Video Answer


1 Answers

You should change your method like this:

@objc private func pause() -> MPRemoteCommandHandlerStatus {
    player?.pause()
    playButton.setImage(UIImage(named: "icon-play")?.alwaysTemplate, for: .normal)
    delegate?.playerViewDidPause()
    return .success
}

and everything will work like a charm😀

like image 78
Bartłomiej Semańczyk Avatar answered Sep 28 '22 08:09

Bartłomiej Semańczyk