简体   繁体   English

从外围设备启动CoreBluetooth重新连接

[英]Initiating CoreBluetooth reconnect from peripheral

I've got an iPhone, I've got a bluetooth low energy (aka Bluetooth 4.o) device. 我有一个iPhone,我有一个蓝牙低功耗(又称为Bluetooth 4.o)设备。 The two have connected in the past. 两者过去曾有联系。 But now they're apart. 但是现在他们分开了。 Something happened, words were said that couldn't be taken back, and now they've disconnected. 发生了一些事情,有人说无法挽回的话,现在他们已经断开了。

Now they're in the same room again. 现在他们又在同一个房间。 The BTLE device wants to connect again. BTLE设备想要再次连接。 It doesn't want to wait for the iPhone to call it. 它不想等待iPhone调用它。 It's taking the initiative. 它是主动的。 It wants to talk to the iPhone, and get that app they used to share launched again. 它想与iPhone通话,并再次启动他们曾经共享的应用程序。

How do I set up the iPhone code to support this? 如何设置iPhone代码以支持此功能?

(Wow, corny.) (哇,老大。)

You have to leave the app connecting to the device, so when the device becomes available the app will connect to it (so long as the app is alive). 您必须保持该应用程序与设备的连接,因此当该设备可用时,该应用程序将与其连接(只要该应用程序处于活动状态)。 Just call [centralManager connectPeripheral] on the CMPeripheral, so the phone will keep listening for the device and connect immediately when it sees it. 只需在CMPeripheral上调用[centralManager connectPeripheral],电话就会继续监听该设备,并在看到该设备时立即进行连接。 That doesn't time out, so you can just leave it running forever. 这不会超时,因此您可以使其永远运行。

If no app is to connect to the peripheral, there's nothing the peripheral can do to change that. 如果没有应用程序要连接到外围设备,则外围设备无法进行任何更改。

This is a little late, but here's what I would do to accomplish this: 这有点晚了,但是这是我要做的:

  • When your device wants to connect, have it advertise a special service. 当您的设备想要连接时,请它宣传一项特殊服务。
  • Assuming the phone is already scanning for devices, it will see the service and you can auto-connect to it. 假设手机已经在扫描设备,它将看到该服务,您可以自动连接到该设备。
  • Now you can have the periphal trigger whatever you like on the central by updating a characteristic, etc. 现在,您可以通过更新特征等来让中枢触发您想要的任何触发。

Of course, this relies on the phone scanning at the time you need the action to trigger, but that is the nature of the beast. 当然,这取决于您需要触发操作时的电话扫描,但这就是野兽的本质。

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

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