Can iOS (iPhone or iPad) app have Core Bluetooth (BTLE) central manger and peripheral manager objects at same time?
Can they operate asynchronously, or does main app thread need to make them share (switch back and forth).
Sharing conceptual algorithm would be: disable peripheral manager, enable central manager and do central functions, and then, disable central mgr, enable peripheral mgr, and do peripheral functions (that is, send automatic nofications, and wait for and respond to remote characteristic commands), repeat...
BACKGROUND GORY DETAILS: We have a local system with multiple iOS devices and multiple non-iOS devices that need to inter-communicate by BTLE. The non-iOS devices all use Broadcom BCM20732 Bluetooth LE chip. But hardware is not ready yet, so I'm using iOS devices to emulate the non-iOS, which requires simultaneous central AND peripheral functionality, ie. 1. act as central to periodically interrogate multiple other non-iOS devices in system. 2. act as peripheral to respond to requests for data from iOS user interface devices.
I got it working. I just started with the Apple "BTLE central peripheral transfer", then first delted the -35 db bug that it has (search for "-35" then delete the if(){ return }), then I combined both the central.m and the peripheral.m into a single UIViewController .m file, added a UISwitch to select one of two service UUID's, and modified the peripheral sender to automatically increment the text field (after init'ing it to ASCII '0').
I had two iPad mini's continuously each sending the incrementing number to the other side. It got up to over 900 transfers and then hung. But I've seen the Apple "BTLE c p transfer" always hang after a few minutes, requiring iPad restart to continue. I ended app at both iPad's and cycled power, re-started app, and they got up to 1600 increments, and then hung.
To solve the hang, I'll add resource control to prevent central and peripheral managers from connecting at same time, as per Abo's recommendation.
Yes they can but if your phone is now in peripheral mode and is connected, you have to make sure that it disconnects before switching to central mode and trying to connect with other devices and vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With