MPRemoteCommandCenter не получает триггеры команд - PullRequest
0 голосов
/ 21 мая 2018

Я настроил функцию, подобную этой

 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).

IВ настройках моего проекта уже включен режим звукового фона.

Есть идеи?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...