MPRemoteCommandCenter не получает триггеры команд
Я настроил такую функцию
func setupRemoteCommandCenter(enable: Bool) {
do{
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeDefault, options: AVAudioSessionCategoryOptions.allowBluetooth)
}
catch {
print("Setting category failed.")
}
let remoteCommandCenter = MPRemoteCommandCenter.shared()
remoteCommandCenter.pauseCommand.isEnabled = enable
remoteCommandCenter.playCommand.isEnabled = enable
remoteCommandCenter.stopCommand.isEnabled = enable
remoteCommandCenter.togglePlayPauseCommand.isEnabled = enable
if enable {
remoteCommandCenter.pauseCommand.addTarget(self, action: #selector(airPodsTap))
remoteCommandCenter.playCommand.addTarget(self, action: #selector(airPodsTap))
remoteCommandCenter.stopCommand.addTarget(self, action: #selector(airPodsTap))
remoteCommandCenter.togglePlayPauseCommand.addTarget(self, action: #selector(airPodsTap))
} else {
remoteCommandCenter.pauseCommand.removeTarget(self, action: #selector(airPodsTap))
remoteCommandCenter.playCommand.removeTarget(self, action: #selector(airPodsTap))
remoteCommandCenter.stopCommand.removeTarget(self, action: #selector(airPodsTap))
remoteCommandCenter.togglePlayPauseCommand.removeTarget(self, action: #selector(airPodsTap))
}
}
Следуя документации Apple, но я не могу постоянно получать события от внешней гарнитуры (проводной / или Bluetooth).
Я уже включил режим звукового фона в настройках своего проекта.
Есть идеи?