Ios MPRemoteCommandCenter未接收命令触发器
我已经设置了这样一个函数Ios MPRemoteCommandCenter未接收命令触发器,ios,iphone,swift,record,mpremotecommandcenter,Ios,Iphone,Swift,Record,Mpremotecommandcenter,我已经设置了这样一个函数 func setupRemoteCommandCenter(enable: Bool) { do{ try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeDefault, options: AVAudioSessionCategoryOptions.allowBluetooth)
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))
}
}
遵循苹果的文档,但我无法始终从外部耳机(有线/或蓝牙)接收事件
我已经在项目设置中启用了音频背景模式
有什么想法吗?我也有同样的问题,有人能帮我们吗?