简体   繁体   English

通过iOS 8小部件断开蓝牙设备

[英]Disconnect Bluetooth device via iOS 8 Widget

I am developing a Bluetooth Low Energy (4.0) device that works with an iOS app and uses CoreBluetooth. 我正在开发可与iOS应用程序一起使用并使用CoreBluetooth的Bluetooth Low Energy(4.0)设备。 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. 但是,既然iOS 8允许开发人员实现自定义窗口小部件,我想在UINotification“今日”中心中显示“断开连接”按钮。

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. 我能够在小部件类中创建一个新的蓝牙对象,并从iOS系统检索蓝牙连接,但是即使此时我断开了BT设备的连接,它仍将在应用程序内部保存一个引用。

Can anyone offer any insight on wonder what I am trying to do is possible? 谁能提供任何见解,使我纳闷我想做什么?

You could possibly use a shared NSUserDefaults database to transfer data between your app and extension. 您可以使用共享的NSUserDefaults数据库在应用程序和扩展程序之间传输数据。 You may also be interested in NSUserDefaults key value observing . 您可能也对NSUserDefaults键值观察感兴趣。

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). 但是,另一种选择是为包含的应用程序实现自定义URL方案 ,然后使用openURL打开包含的应用程序并执行断开操作(或您希望扩展程序执行的其他任何操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM