如何从 MPRemoteCommandCenter 禁用所有 MPRemoteCommand 对象
How to disable all the MPRemoteCommand objects from MPRemoteCommandCenter
Apple doc 表示“您可以通过将其启用的 属性 设置为 NO 来禁用相应的 MPRemoteCommand 对象。”
我参考了 Is there a public way to force MPNowPlayingInfoCenter to show podcast controls? 并且我能够 disable/enable 锁定屏幕控制的特定命令。
但是我想从锁屏控件中禁用所有控件,因为我正在播放收音机并且它不支持任何操作 - “Play/Pause/Next/Previous”
我尝试了以下代码片段:
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];
但是没有用。禁用所有功能可在锁定屏幕上启用暂停、上一个、下一个按钮。
任何帮助将不胜感激。
是"you can disable the corresponding MPRemoteCommand
object by setting its enabled property to NO."
但是如果您要禁用所有按钮,则不要删除目标或添加目标,这可能什么都不做。没有文档解释为什么我们必须这样做this 但它是这样工作的。
试试下面的代码,这会起作用。
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:)];
Apple doc 表示“您可以通过将其启用的 属性 设置为 NO 来禁用相应的 MPRemoteCommand 对象。”
我参考了 Is there a public way to force MPNowPlayingInfoCenter to show podcast controls? 并且我能够 disable/enable 锁定屏幕控制的特定命令。
但是我想从锁屏控件中禁用所有控件,因为我正在播放收音机并且它不支持任何操作 - “Play/Pause/Next/Previous”
我尝试了以下代码片段:
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];
但是没有用。禁用所有功能可在锁定屏幕上启用暂停、上一个、下一个按钮。 任何帮助将不胜感激。
是"you can disable the corresponding MPRemoteCommand
object by setting its enabled property to NO."
但是如果您要禁用所有按钮,则不要删除目标或添加目标,这可能什么都不做。没有文档解释为什么我们必须这样做this 但它是这样工作的。
试试下面的代码,这会起作用。
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:)];