Pair and Connecting to Bluetooth Classic Speaker iOS - ios

I realise most of the searches are quite old on this topic and not after Core Bluetooth now supports more than just BLE connections (https://developer.apple.com/videos/play/wwdc2019/901?time=556).
Simply by running the RxBluetoothKit example app I am able to discover my speaker and inspect its services. However I am unsure how to actually get the speaker to pair with the phone, after a while the speaker disconnects. I am struggling to get information on the protocol and/or how to proceed.
Or is this still not possible: "And so if you're calling connect on a BR/EDR device, if your app is in foreground, then we'll try to make a connection out to that device for you." - it seems like querying and communication with an already paired device is what they were getting at in the talk.
Thanks in advance.

Related

Bluetooth peripheral does not pair

I have written an apple watch app to try to communicate with a bluetooth peripheral which has implemented some custom encryption and pairing process I already managed to implement correctly.
The device seems not to conform to standards and as such does not indicate that it needs encryption through its chatacteristic properties. After going through the pairing I can write values to it and recieve notifications.
The problem is that when I disconnect and connect again I have to go through the pairing process again. Also I have noticed that after pairing via other apps the device does a long beep sound which seems missing when I pair it through my app.
Is there any way to force pairing/binding in CoreBluetooth?

iOS Detect Bluetooth connection/disconnection

Is it possible to be notified when a Bluetooth Device is connected or disconnected from iOS even when my app is in background ?
On Android, I use the ACTION_ACL_CONNECTED and ACTION_ACL_DISCONNECTED events. But I cannot find equivalents for iOS.
I found the CBCentralManager that can be used to monitor Bluetooth events, but my functions aren't called when a bluetooth device is connected/disconnected, only when I enable/disable the bluetooth. Is it an error on my side or is it normal ?
I also found the doc about Audio Route changes, that can also be an idea to detect the bluetooth connections/disconnections. Just check the kind of new route and detect the connected bluetooth devices at that time.
In the doc, I also found NSNotification types like IOBluetoothHostControllerXXX but nothing is explained about them. Did someone already used them ?
Is there something better or am I missing something ?
You cannot receive notifications about the connection and disconnection of Bluetooth peripherals generally. You can get connection and disconnection events for BLE peripherals that your app connects to.
For example, if your app initiates a connection to a heart rate sensor then you will get a call to your CBCentralManagerDelegate connection function when the connection succeeds. If that device subsequently is switched off or goes out of range then you will get a call to the disconnection delegate method.
If some other app initiates and makes the connection then you will not get a callback.
As you mentioned, you can monitor audio route changes to infer that a Bluetooth audio device has been connected/disconnected, but this will also fire when headphones are plugged in.

iBeacons and CBService Broadcast simultaneously

Is it possible to simultaneously broadcast my iOS app as an iBeacon and at the same time publish a service?
My app currently advertises a service, which works perfectly fine. My client app (central) is able to find the peripheral, connect, obtain the service and read data from the characteristic. However, if I update my server app (peripheral) to start broadcasting as an iBeacon emitter in addition to the service, I am no longer able to find services that I setup to advertise on the client app (central).
The idea of this is that I want to be able to read information from the server (peripheral) app when in close proximity from the client (central).
Is this technically feasible?
I was thinking about turning off iBeacon transmission when a device comes into close proximity and then starting the service broadcast, but there is no API in Core Bluetooth that calls back to the emitter when a client device enters the region being advertised.
Is this doable? Is there a workaround that would achieve something along these lines? I would like to avoid any networking, as this should be an offline solution.
Taz, For sure you can be an iBeacon and you can look for iBeacons. What I did and what I see other doing is combining iBeacons with other services, such as the CloudKit [which yes, means networking too] to add functionality to their basic functionality.
That said I can imagine an app in which your iBeacons switch to a different protocol when they see each other, the challenge; how-to negotiate a channel/UUIDs for a BLE peripheral/central pair.
I am still in the process of building, but have implemented something similar over the past months... in short you hardcode an initial channel to start your BLE conversation, your first and only exchange on said channel being to agree a new BLE one to use.

How to send data to an iphone which is turned into a iBeacon?

how is it possible to send data to an iPhone which acts as an iBeacon?
I am looking for an process as the following:
Search nearby iBeacons
Connect to some iBeacon
Exchange data between the devices
Does anybody know how to put the different bluetooth functions together to make
this possible?
thx in advance
Standard iBeacons are transmit-only devices that can be seen by mobile devices, but don't actually "connect" to them or exchange data.
But you can still do what you are asking if you have an app on all devices as well as a web service to do the data transfer. This would allow devices A and B to detect each other when they are nearby and exchange data. Here's how:
Your app on devices A and B alternates between acting as an iBeacon (advertising its presence with an application-specific identifier and a phone-specific identifier) and ranging for iBeacon signals including the application-specific identifier.
During its ranging cycle, your app on device A will detect an iBeacon transmission from device B, which includes both your application identifier and the device identifier of B.
App A then makes a "write" call to the web service with a source of "A" and a destination of "B", along with any data you want to transfer, like "Device A says hello to device B."
The app would also periodically make a "read" call to the web service. In this example, device B would read any information destined for B, and the web service would return a record that device A had send it a message with the data "Device A says hello to device B."
Because the same process is also running on both phones, this communication can happen both ways.
iBeacon is a proximity technology and isn't designed for data interchange. However, since the Bluetooth stack is going to be active on your iPhone acting as the beacon (so it can advertise its proximity UUID), you can use Core Bluetooth to connect to the beacon and exchange data between the devices.
Does it specifically need to use iBeacon technology? The reason I ask is that from reading your description of the process, you could achieve the same thing using iOS 7's Multipeer Connectivity. It's able to abstract out all the technical complexities of connecting 2 iOS devices together regardless of the interface, be it WiFi or Bluetooth. I've managed to build something similar using MCNearbyServiceBrowser, MCNearbyServiceAdvertiser, and MCSession classes.

bluetooth low energy advertising packet and topology

I want to advertise a single id lets say "stackoverflow1" on a ble device. So people close to the sensor can get this message (welcome to wwdc2012) as popups on the iPhone. That's it! meaning that there is no update on the value or anything else in other words I just want to know which room I came in. In another room there's another sensor adversing "stackoverflow2".
Now the question is, should I put the rooms' sensor (advertiser) as Peripherals and visitors' iPhones as Centrals?
If your answer is yes, can I send this Id in advertising packet? i.e. can I skip connection to the room's peripheral? Please guide me a little but on this
Thanks
Yes, the iPhones should be centrals and the in-room device should be a peripheral. It's perfectly fine to put enough data in the advertisement that the iOS app can do something useful after simply seeing the peripheral advertised without actually connecting to it. That way, multiple centrals/phones can detect proximity at once without a single phone tying up an exclusive connection to the device. Instead of specifying the room in the service name, you should be able to put it in the advertisement data for the device, giving them all the same service name. That way the iOS app doesn't need to know the completely list of rooms (i.e. services) in advance and they can be added to without changing the app.
In short, the gist of what you described should work fine, and seems like a sound approach to me.
You can include information in the advertisement from the peripheral as "Manufacturer Specific" data. Then the iOS application can get it from the advertisement data dictionary using the CBAdvertisementDataManufacturerDataKey.

Resources