awesome-tips / iOS-Tips

iOS知识小集
MIT License
3.29k stars 451 forks source link

Adaptation for iOS 13 - [MPRemoteCommand add: target:] crash #40

Open freedani opened 5 years ago

freedani commented 5 years ago

Example:

- (void)playAction:(MPRemoteCommand *)sender {
    // do something
}

- (void)func {
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    // crash here
    [commandCenter.playCommand addTarget:self action:@selector(playAction:)];
}

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

https://forums.developer.apple.com/thread/121540

Fix in iOS 13:

- (MPRemoteCommandHandlerStatus)playAction:(MPRemoteCommand *)sender {
    // do something
    return MPRemoteCommandHandlerStatusSuccess;
}