Check Bluetooth off without Systemhint - ios

I'm developing an app that connects to a peripheral by BLE.
How do I check bluetooth is off without an iOS system dialog?
Currently I listen to didUpdateState in the CBCentralManagerDelegate. But if bluetooth is powered off I get the event AND a system ui dialog telling me to activate bluetooth in settings.
Is there another way to check?

Make sure you are specifying false for the CBCentralManagerOptionShowPowerAlertKey when you instantiate your CBCentralManager object

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?

Why is the prompt to allow the app to access Bluetooth not being shown after initializing CBCentralManager?

I am attempting to use CoreBluetooth and have setup both NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription in my info.plist. On the tap of a button my CBCentralManager is initialized and the centralManagerDidUpdateState(_ central: CBCentralManager) delegate method is called.
However, I am not prompted to allow the app to access Bluetooth permissions. I do see the default prompt to turn on Bluetooth when Bluetooth is off, but no prompt to allow the app to use Bluetooth when Bluetooth is on. Instead, the delegate method is continually called.
From my understanding the prompt should show as soon as you initialize the CBCentralManager. Any ideas what could be going on here? I am using a phone with iOS 14 to test.

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.

Disable "Location Accuracy" message when using iBeacon

I have an app that uses iBeacon. I plan to provide all of the feedback about the state of Location Services and Bluetooth to the user within the app.
The problem is: When I disable Bluetooth while the app is running. An alert view comes up titled "Location Accuracy" saying "Turning on Bluetooth will improve location accuracy." This degrades from the user experience that I am trying to set up. I want to guide users into turning on Bluetooth using custom UI.
I would like to disable this alert. Is that possible?
You can't. iBeacon based on Bluetooth so it just not work without turning it On.
Upd. but of course you can check that bluetooth disabled with CBCentralManager and inform user in other way before using iBeacon code

What, exactly, is a BLE connected device on iOS?

The CBCentralManager retrieveConnectedPeripherals method says it gets "the list of the peripherals currently connected to the system." The definition of system is a bit ambiguous here.
Does this mean I get a list of peripherals connected to my app, or a list of peripherals connected to any app?
If I can get peripherals connected to another app, does this also mean multiple apps can connect to the same peripheral?
Can this only happen if the app is in the foreground, or do I need to allow for the possibility that a background app is sending commands to a peripheral I think my app owns?
BLE 4.0 enabled devices are usually connected with CBCentralManager unboundly. What is bounded and unbounded connection, you can know from this link.
One BLE 4.0 enabled device can be connected with only one master device thus enhancing secured connectivity. You should follow this link.
Whether in foreground of background, if the connection exists, the BLE slave device won't get connected with another app or device.

Resources