首页 > 解决方案 > 不支持的操作方法签名。必须返回 MPRemoteCommandHandlerStatus

问题描述

每当我在 iOS 13+ 上运行模拟器时都会出现此错误。一切都适用于 iOS 12 及更低版本,所以我不确定在这里做什么。有什么我可以更改/编辑的东西来react-native-music-control为 iOS 13 工作吗?

Exception 'Unsupported action method signature. Must return MPRemoteCommandHandlerStatus or take a completion handler as the second argument.' was thrown while invoking enableControl on target MusicControlManager with params ( pause, 1, { } )

标签: react-native

解决方案


react-native-music-control可能还没有更新它的 iOS MediaPlayer 方法。一种常见的方法是 MediaPlayer 的addTarget. 从 iOS 13 开始,此方法必须返回一个MPRemoteCommandHandlerStatus. 它过去在以前的 iOS 版本中不返回任何内容。

例如,如果您有一个play在点击播放按钮时被调用的方法:

- (void) play { 
/* start playing */
}

您可能正在注册它play以在触发媒体播放器的play命令时调用:

[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(play)];

然后,您只需要简单地更改您的play方法以返回MPRemoteCommandHandlerStatus如下所示:

- (MPRemoteCommandHandlerStatus) play
{
    // if successfully played
    return MPRemoteCommandHandlerStatusSuccess;

    // else if there's an issue
    // return MPRemoteCommandHandlerStatusCommandFailed;
}

这是在Objective-C中。在 Swift 中更改返回值也很简单。

参考:https ://developer.apple.com/documentation/mediaplayer/mpremotecommand/1622895-addtarget?language=objc


推荐阅读