Megha
Megha

Reputation: 41

How to know the Bluetooth device connection/disconnection status callbacks to an iOS application running in background?

As per apple documents apps running in background cannot receive callbacks except for apps which are location based, VOIP, Newstand, Music player or APNS enabled. How to receive the connection status callbacks in that case? The app is making use of AVAudioSession instance as:

try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with:AVAudioSessionCategoryOptions.allowBluetooth)

And listens to notifications as:

NotificationCenter.default.addObserver(self,selector:#selector(handleRouteChange), name: .AVAudioSessionRouteChange,object: AVAudioSession.sharedInstance())

This is called in the launch of the application.

Upvotes: 2

Views: 609

Answers (1)

mag_zbc
mag_zbc

Reputation: 6982

You can use the bluetooth-central background mode. According to Background modes documentation

(...) new data arriving from the peripheral causes the system to wake up the app so that it can process the data. The system also wakes up the app to process accessory connection and disconnection notifications.

Upvotes: 2

Related Questions