Как отключить все объекты MPRemoteCommand из MPRemoteCommandCenter
В Apple doc сказано: "Вы можете отключить соответствующий объект MPRemoteCommand, установив для его свойства enabled значение NO".
Я упомянул Есть ли публичный способ заставить MPNowPlayingInfoCenter показывать элементы управления подкаста? и я смог отключить / включить определенную команду на экране блокировки управления.
Однако я хочу отключить все элементы управления от управления экраном блокировки, так как я играю радио, и оно не поддерживает ни одно из действий - "Воспроизведение / Пауза / Далее / Назад"
Я попробовал следующий фрагмент кода:
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];
Однако это не сработало. Отключение всего включает кнопку паузы, предыдущей, следующей кнопки на экране блокировки. Любая помощь будет принята с благодарностью.
1 ответ
Да, вы можете отключить соответствующие MPRemoteCommand
объект, установив его свойство enabled в NO."
Но если вы отключаете все кнопки, не удаляйте цель и не добавляйте цель, которая, вероятно, ничего не изменит. Нет документа, объясняющего, почему мы должны это делать, но это работает так.
Попробуйте следующий код, это будет работать.
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:)];