user2768806
user2768806

Reputation: 21

App crashes in background while bluetooth connection lost for long time

I am developing an app which will communicate with bluetooth low energy devices. And I am displaying the heart rate in UI. It works fine in foreground and background while bluetooth is in connection. But my problem is that while connection of bluetooth device lost longer while app is in background, my app crashed. showing the crash report as :

MyApp[565] has active assertions beyond permitted time: 

Upvotes: 2

Views: 1118

Answers (2)

allprog
allprog

Reputation: 16790

With Core Bluetooth background communication must be implemented either with characteristic change notifications or indications. You are keeping the app running for too long after being brought to background and iOS is killing it forcefully. I suppose you are using the beginBackgroundTaskWithExpirationHandler: method to keep some timers running. This doesn't work for long periods of time. The limit is around 10 minutes but it may depend on other factors too.

The Core Bluetooth Programming Guide contains a pretty concise description of how backgrounding has to be handled. Practically, your app needs to subscribe on either notifications or indications of the heart rate characteristic and react to it only when the callbacks happen. The app should keep running when backgrounded only if it is doing some uninterruptible task, e.g. non-resumable network operations.

Upvotes: 1

Raveen Beemsingh
Raveen Beemsingh

Reputation: 554

i am assuming that you are on iOS 6.1

Are you handling device disconnect using the following delegate methods of CBCentralManager

– centralManager:didDisconnectPeripheral:error:
– centralManager:didFailToConnectPeripheral:error:

also i suspect there is no device discovery when in background, so you might have to handle that logic in your code

Upvotes: 0

Related Questions