3

I'd like to detect when a bluetooth device or network disconnects, even when my app isn't running.

In Android, you can register to be notified when the bluetooth adapter changes state.

http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_CONNECTION_STATE_CHANGED

I don't need to bring the app to the foreground. I just need to record the fact that it disconnected, a timestamp, and some location data. Once the user brings the app back up, I'll be accessing that data to provide them info of where the bluetooth device disconnected.

(I'm using RubyMotion, but that isn't super relevant for this question. Objective-C answers are fine.)

Jamon Holmgren
  • 23,738
  • 6
  • 59
  • 75

1 Answers1

1

You might want to take a look here for background modes. Will any of those work for you? There are more in ios 7. Some background modes may be compatible with ios 6 as well though. Are you using Core Bluetooth? Theres a background mode for that

Andrew
  • 15,357
  • 6
  • 66
  • 101
  • I could use Core Bluetooth. In the planning stages of this feature. Looking into the background mode right now (the iOS 7 multitasking is pretty limited, from what I can see, but I could be wrong). – Jamon Holmgren Jul 08 '13 at 20:58
  • take a look at the bluetooth-central and bluetooth-peripheral background modes. They are available in iOS 5 and 6, respectively. – Andrew Jul 08 '13 at 21:00
  • I'm digging into the docs, but have yet to find a clean code example. I'll keep working at it. Apple docs suck. – Jamon Holmgren Jul 08 '13 at 21:10
  • 1
    This may be useful: http://stackoverflow.com/questions/9896562/what-exactly-can-corebluetooth-applications-do-whilst-in-the-background – Andrew Jul 08 '13 at 21:12
  • Hm, unfortunately I'm getting the sense that this isn't really possible right now. There are issues with each implementation suggested so far, such as not tracking bluetooth connect/disconnect while the app is not running (without an app open in the meantime). – Jamon Holmgren Jul 10 '13 at 21:42