gpt4 book ai didi

ios - 如何从 MPRemoteCommandCenter 禁用所有 MPRemoteCommand 对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:12:10 30 4
gpt4 key购买 nike

Apple doc说“您可以通过将其启用属性设置为 NO 来禁用相应的 MPRemoteCommand 对象。”

我提到了 Is there a public way to force MPNowPlayingInfoCenter to show podcast controls?并且我能够在锁定屏幕控制上禁用/启用特定命令。

但是我想禁用锁屏控制中的所有控件,因为我正在播放 radio 并且它不支持任何操作 - “播放/暂停/下一首/上一首”

我尝试了以下代码片段:

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];

但是没有成功。禁用所有功能可在锁定屏幕上启用暂停、上一个、下一个按钮。任何帮助将不胜感激。

最佳答案

是的“您可以通过将其启用属性设置为 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:)];

关于ios - 如何从 MPRemoteCommandCenter 禁用所有 MPRemoteCommand 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38993801/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com