如何从MPRemoteCommandCenter禁用所有MPRemoteCommand对象 [英] How to disable all the MPRemoteCommand objects from MPRemoteCommandCenter

查看:953
本文介绍了如何从MPRemoteCommandCenter禁用所有MPRemoteCommand对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple doc 说你可以禁用通过将其enabled属性设置为NO来对应的MPRemoteCommand对象。

Apple doc says "you can disable the corresponding MPRemoteCommand object by setting its enabled property to NO."

我提到是否有公共方式强制MPNowPlayingInfoCenter显示播客控件?我能够禁用/启用特定命令锁定屏幕控制。

I referred Is there a public way to force MPNowPlayingInfoCenter to show podcast controls? and I was able to disable/enable a particular command on lock screen control.

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

However I want to disable all the controls from lock screen control since I am playing a radio and it do not support either of the action - "Play/Pause/Next/Previous"

我尝试了以下代码片段:

I tried following code snippet:

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

然而它不起作用。禁用所有内容可启用锁定屏幕上的暂停,上一个,下一个按钮。
任何帮助将不胜感激。

However it didn't work. Disabling everything enables pause, previous, next button on lock screen. Any help would be greatly appreciated.

推荐答案

是你可以通过设置它来禁用相应的 MPRemoteCommand 对象启用属性为NO。

Yes "you can disable the corresponding MPRemoteCommand object by setting its enabled property to NO."

但是如果要禁用所有按钮,则不要删除目标或添加可能无效的目标。没有文件解释为什么我们必须这样做但是它以这种方式工作。

But If you are disabling all the buttons then don't remove the target or add a target which will probably do nothing. There is no document explaining why we have to do this but it works this way.

尝试以下代码,这将有效。

Try the following code this will work.

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

这篇关于如何从MPRemoteCommandCenter禁用所有MPRemoteCommand对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆