4

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

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.

Community
  • 1
  • 1
Anoop Nyati
  • 339
  • 2
  • 11

1 Answers1

6

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:)];
Sarat Patel
  • 856
  • 13
  • 32
  • Thanks Sagar. Its working. Though not sure how target is related to it. I had added feedback at Apple for the same. – Anoop Nyati Aug 24 '16 at 10:52
  • Hi I tried this but some white overlay appearing on the player screen and in control center i cant able to new buttons. DO you have any idea what will be the issue? – IamDev Apr 21 '17 at 13:47