【问题标题】:How to disable all the MPRemoteCommand objects from MPRemoteCommandCenter如何从 MPRemoteCommandCenter 禁用所有 MPRemoteCommand 对象
【发布时间】:2016-12-23 22:39:53
【问题描述】:

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

我推荐了Is there a public way to force MPNowPlayingInfoCenter to show podcast controls?,我能够禁用/启用锁定屏幕控制上的特定命令。

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

我尝试了以下代码 sn-p:

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

但是没有用。禁用一切会启用锁定屏幕上的暂停、上一个、下一个按钮。 任何帮助将不胜感激。

【问题讨论】:

    标签: ios xcode mpnowplayinginfocenter control-center


    【解决方案1】:

    是的“您可以通过将其 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:)];
    

    【讨论】:

    • 谢谢萨加尔。它的工作。虽然不确定目标与它有什么关系。我在 Apple 也为此添加了反馈。
    • 您好,我试过了,但是播放器屏幕和控制中心出现了一些白色覆盖层,我无法使用新按钮。你知道会是什么问题吗?
    猜你喜欢
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-09-24
    • 2023-02-23
    • 1970-01-01
    • 2021-03-10
    • 2020-06-06
    相关资源
    最近更新 更多