I am integrating CarPlay functionality in my existing iOS Music App. I have added Shuffle button in CPNowPlayingTemplate. CarPlay simulator is showing this button but it is not updating its state when I change the value of MPRemoteCommandCenter.shared().changeShuffleModeCommand.currentShuffleType its handler.
var defaultShuffleButton = CPNowPlayingShuffleButton { button in
if MPRemoteCommandCenter.shared().changeShuffleModeCommand.currentShuffleType == MPShuffleType.off {
MPRemoteCommandCenter.shared().changeShuffleModeCommand.currentShuffleType = MPShuffleType.collections
button.isSelected = true
} else if MPRemoteCommandCenter.shared().changeShuffleModeCommand.currentShuffleType == MPShuffleType.collections {
MPRemoteCommandCenter.shared().changeShuffleModeCommand.currentShuffleType = MPShuffleType.items
button.isSelected = true
} else if MPRemoteCommandCenter.shared().changeShuffleModeCommand.currentShuffleType == MPShuffleType.items {
MPRemoteCommandCenter.shared().changeShuffleModeCommand.currentShuffleType = MPShuffleType.off
button.isSelected = false
}
}
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
self.interfaceController = interfaceController
MPRemoteCommandCenter.shared().changeShuffleModeCommand.isEnabled = true
CPNowPlayingTemplate.shared.updateNowPlayingButtons([defaultShuffleButton])
}
I have gone through the Apple documentation but could not find anything regarding this issue. It says in your handler, change the shuffle mode to the new value I can see in the logs that value of MPRemoteCommandCenter is being changed but CPNowPlayingTemplate is not updating the button states.
Thanks in advance!