Biniou
Biniou

Reputation: 133

iOS CoreBluetooth can't receive notifications in background

I am writing an app that should be able to connect to a Ble device and receive update for one of the characteristics.

I am able to discover the device I want to connect to, connect to it, and register for notifications on the characteristic I am interested in.

Every time the app receives an update for this characteristic it will send the value to a server via an http call.

Everything is working fine in the foreground but as soon as I background my app, it stops receiving the updates. I added

<key>UIBackgroundModes</key>
<array>
    <string>bluetooth-central</string>
    <string>bluetooth-peripheral</string>
</array>

to my plist file. I am testing on an iPhone6 plus running iOS 9.3. Developing with Xcode 8 and swift 2.3. Notifications are being sent every 10 seconds by the Ble device but the app won't handle the notifications in the bakground.

Upvotes: 0

Views: 824

Answers (2)

Biniou
Biniou

Reputation: 133

I found the issue.

I was instantiating the object taking care of all the scanning, connecting, reading, etc in my AppDelegate. As soon as I moved it to a ViewController it started working just fine in the background. Not sure why.

Upvotes: 2

neprocker
neprocker

Reputation: 170

You will need to add capabilities of Required background mode for Bluetooth in Project/capabilities Since you are able to use the blue tooth while foreground, I believe you have added necessary entitlements

Upvotes: 0

Related Questions