每当我在 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-music-control可能没有更新其 iOS MediaPlayer 方法。一种常见的方法是 MediaPlayer 的addTarget. 从 iOS 13 开始,此方法必须返回一个MPRemoteCommandHandlerStatus. 它曾经在以前的 iOS 版本中不返回任何内容。
例如,如果您有一个play在点击播放按钮时调用的方法:
- (void) play {
/* start playing */
}
Run Code Online (Sandbox Code Playgroud)
您可能正在注册它play以在play触发媒体播放器的命令时调用:
[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(play)];
Run Code Online (Sandbox Code Playgroud)
然后,您所需要的只是简单地更改您的play方法以返回MPRemoteCommandHandlerStatus这样的:
- (MPRemoteCommandHandlerStatus) play
{
// if successfully played
return MPRemoteCommandHandlerStatusSuccess;
// else if there's an issue
// return MPRemoteCommandHandlerStatusCommandFailed;
}
Run Code Online (Sandbox Code Playgroud)
这是在Objective-C中。在 Swift 中更改返回值也很简单。
参考:https : //developer.apple.com/documentation/mediaplayer/mpremotecommand/1622895-addtarget?language=objc
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |