App crashing on iOS 13 - Must return MPRemoteCommandHandlerStatus or take a completion handler as the second argument.

I'm testing my app on an XS simulator running iOS 13 from the XCode beta application. It builds without any errors. However, the app crashes at startup with the following error.


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


My app runs just fine on all previous versions of iOS. I looked through the developer release notes for iOS 13 and was unable to find anything about changes to the MPRemoteCommandCenter. The app is crashing at line 03 in the following code block.


  MPRemoteCommandCenter * commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
  commandCenter.playCommand.enabled = YES;
  [commandCenter.playCommand addTarget:self
    action:@selector(resume)];


Does anyone have insight on this issue? Might this be a bug with iOS 13 or the simulator?

Accepted Reply

According to Apple's docs, the method signature of the selector needs to return a

MPRemoteCommandHandlerStatus
. I updated my method,
resume
, to return the
MPRemoteCommandHandlerStatusSuccess
constant. This eliminated the error and now my app works as intended. I wonder why apple chose iOS 13 to be the release to start enforcing this behavior. It was also annoying that they did not include this in their release notes.

Replies

According to Apple's docs, the method signature of the selector needs to return a

MPRemoteCommandHandlerStatus
. I updated my method,
resume
, to return the
MPRemoteCommandHandlerStatusSuccess
constant. This eliminated the error and now my app works as intended. I wonder why apple chose iOS 13 to be the release to start enforcing this behavior. It was also annoying that they did not include this in their release notes.

Could you please share code for this solution?


Update: I've found a way to silence the warnings. After exposing your addTarget method to MPRemoteCommandHandlerStatus you then set your commandCenter command to isEnabled = true


let commandCenter = MPRemoteCommandCenter.shared()
        
commandCenter.playCommand.addTarget { (_) -> MPRemoteCommandHandlerStatus in
     self.player.play()
     self.playPauseButton.setImage(#imageLiteral(resourceName: "pause"), for: .normal)
     self.miniPlayPauseButton.setImage(#imageLiteral(resourceName: "pause"), for: .normal)
     self.setupElapsedTime(playbackRate: 1)
            
     return .success
}
commandCenter.playCommand.isEnabled = true