如何从MPRemoteCommandCenter禁用所有MPRemoteCommand对象
Apple doc说“你可以通过将其enabled属性设置为NO来禁用相应的MPRemoteCommand对象。”
我提到是否有一种公共方式强制MPNowPlayingInfoCenter显示播客控件? 我能够在锁定屏幕控制上禁用/启用特定命令。
但是我想从锁定屏幕控制中禁用所有控件,因为我正在播放收音机并且它不支持任何操作 – “播放/暂停/下一个/上一个”
我尝试了以下代码段:
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter]; remoteCommandCenter.previousTrackCommand.enabled = NO; [remoteCommandCenter.previousTrackCommand removeTarget:self]; remoteCommandCenter.nextTrackCommand.enabled = NO; [remoteCommandCenter.nextTrackCommand removeTarget:self]; remoteCommandCenter.skipBackwardCommand.enabled = NO; [remoteCommandCenter.skipBackwardCommand removeTarget:self]; remoteCommandCenter.skipForwardCommand.enabled = NO; [remoteCommandCenter.skipForwardCommand removeTarget:self]; remoteCommandCenter.bookmarkCommand.enabled = NO; [remoteCommandCenter.bookmarkCommand removeTarget:self]; remoteCommandCenter.playCommand.enabled = NO; [remoteCommandCenter.playCommand removeTarget:self]; remoteCommandCenter.pauseCommand.enabled = NO; [remoteCommandCenter.pauseCommand removeTarget:self];
但它没有用。 禁用所有内容可启用锁定屏幕上的暂停,上一个,下一个按钮。 任何帮助将不胜感激。
是“您可以通过将其enabled属性设置为NO来禁用相应的MPRemoteCommand
对象。”
但是如果要禁用所有按钮,则不要删除目标或添加可能无效的目标。 没有文件解释为什么我们必须这样做但它以这种方式工作。
尝试以下代码,这将有效。
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter]; remoteCommandCenter.previousTrackCommand.enabled = NO; remoteCommandCenter.nextTrackCommand.enabled = NO; remoteCommandCenter.skipBackwardCommand.enabled = NO; remoteCommandCenter.skipForwardCommand.enabled = NO; remoteCommandCenter.bookmarkCommand.enabled = NO; remoteCommandCenter.playCommand.enabled = NO; remoteCommandCenter.pauseCommand.enabled = NO; [remoteCommandCenter.previousTrackCommand addTarget:self action:@selector(actionDoNothing:)]; [remoteCommandCenter.nextTrackCommand addTarget:self action:@selector(actionDoNothing:)]; [remoteCommandCenter.skipBackwardCommand addTarget:self action:@selector(actionDoNothing:)]; [remoteCommandCenter.skipForwardCommand addTarget:self action:@selector(actionDoNothing:)]; [remoteCommandCenter.bookmarkCommand addTarget:self action:@selector(actionDoNothing:)]; [remoteCommandCenter.playCommand addTarget:self action:@selector(actionDoNothing:)]; [remoteCommandCenter.pauseCommand addTarget:self action:@selector(actionDoNothing:)];