MPRemoteCommandCenter does not work with Bluetooth Handsfree

301 views Asked by At

I want to receive remote control events from Bluetooth Handsfree device, Below mentioned is my set of code for play and pause events.

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

But no such events are triggered. Any help will be appreciated.

1

There are 1 answers

0
Piyush Sharma On

You need to call

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

in

viewWillAppear()

in order to make your application get the desired events.