baudot
baudot

Reputation: 1618

Initiating CoreBluetooth reconnect from peripheral

I've got an iPhone, I've got a bluetooth low energy (aka Bluetooth 4.o) device. 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. It doesn't want to wait for the iPhone to call it. It's taking the initiative. It wants to talk to the iPhone, and get that app they used to share launched again.

How do I set up the iPhone code to support this?

Upvotes: 2

Views: 1173

Answers (2)

William henderson
William henderson

Reputation: 377

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.

Upvotes: 1

Glenn Maynard
Glenn Maynard

Reputation: 57474

(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. 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.

Upvotes: 4

Related Questions