MPRemoteCommandCenter不适用于蓝牙免提

时间:2017-09-19 07:13:55

标签: ios bluetooth mpremotecommandcenter

我想从蓝牙免提设备接收远程控制事件,下面提到的是我的播放和暂停事件代码集。

MPRemoteCommandCenter.shared().nextTrackCommand.isEnabled = true
MPRemoteCommandCenter.shared().previousTrackCommand.isEnabled = true
MPRemoteCommandCenter.shared().nextTrackCommand.addTarget(self, action: #selector(playCommand))
MPRemoteCommandCenter.shared().previousTrackCommand.addTarget(self, action: #selector(previousCommand))

但是没有触发这样的事件。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您需要致电

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

in

viewWillAppear()

为了让您的应用程序获得所需的事件。