1

I am developing a Bluetooth Low Energy (4.0) device that works with an iOS app and uses CoreBluetooth. I have successfully created this app and it interacts with the device just fine. However, now that iOS 8 allows developers to implement custom widgets, I want to display a "Disconnect" button in the UINotification "Today" Center.

The issue is this: I believe I have read that there is no way to communicate between the widget and the app meaning that the widget has it's own container. This also means then that I cannot access the Bluetooth object in the app that is holding the reference to my Bluetooth device from the widget itself in order to disconnect the object. I am able to create a new Bluetooth object inside the widget class and retrieve the bluetooth connection from the iOS system but even I disconnected the BT device at this point, it would still be holding a reference inside the app.

Can anyone offer any insight on wonder what I am trying to do is possible?

AstroCB
  • 12,337
  • 20
  • 57
  • 73
Teddy13
  • 3,824
  • 11
  • 42
  • 69

1 Answers1

2

You could possibly use a shared NSUserDefaults database to transfer data between your app and extension. You may also be interested in NSUserDefaults key value observing.

App extensions are meant to be independent from their containing app, and I'm not sure they were meant for this purpose.

However, another option would be to implement a custom URL scheme for your containing app, and then to use openURL to open your containing app and execute a disconnect action (or anything else you'd like your extension to do).

Community
  • 1
  • 1
Andrew
  • 15,357
  • 6
  • 66
  • 101
  • Thanks for those suggestions, I really appreciate it. It seems that your custom URL Scheme may be the way to go. However, I am intrigued by your suggestion of NSUserDefaults key value observing. How would this work since the widget and the app are essentially independent of each other? Would the app, through the widget still be able to be notified this way? Thanks! – Teddy13 Sep 27 '14 at 02:10
  • 1
    @Teddy13 I'm really not sure if key-value observing would work with bluetooth background modes or not. You could however certainly use `NSUserDefaults` in your `CoreBluetooth` delegate method implementations to at least check if the user has "requested a disconnect" via the widget. – Andrew Sep 27 '14 at 02:19
  • 1
    @Teddy13 But you're right - custom URL schemes are probably the way to go. There just isn't a great way to do any sort of event-based communication between an extension and the containing app. – Andrew Sep 27 '14 at 02:20