1

Whats the default alert action of CBCentralManager when options = nil in initialization?

For the below code,

 bleCentralManager = CBCentralManager(delegate: self, queue: nil)

System pop up is showing. Don't know why. One of available options

let CBCentralManagerOptionShowPowerAlertKey: String

A Boolean value that specifies whether the system warns the user if the app instantiates the central manager when Bluetooth service isn’t available.

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
  • I don't understand. You are talking about pop-up, but there is no pop-up code. What is happening, is that you might have the Bluetooth usage permission to show, that's all. The options of that method are for other stuff (https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/central_manager_initialization_options) – Larme Aug 13 '20 at 15:55
  • @Larme I was talking about the systems permission popup. If I do not set options, why I am still being warned with popup when BLE is off? – Sazzad Hissain Khan Aug 13 '20 at 16:00
  • Because you are still starting the Bluetooth Manager. Next step is to check the CentralManager state, to know if you will start or not the scan. The options here are not related at all. – Larme Aug 13 '20 at 16:13
  • @Larme I want to start BLE but without system popup. How can I do so? I just need to start it to get the status of BLE. – Sazzad Hissain Khan Aug 13 '20 at 16:54
  • 2
    You can't start BLE without getting permission to do so from the user. What would be the point of a permission pop up if apps could simply bypass it? – Paulw11 Aug 13 '20 at 19:52
  • There has never been a way to control the permission popup. There is an option CBCentralManagerOptionShowPowerAlertKey:@No, but In my current testing, that doesn't seem to do anything. At one point, it used to control whether there would be a prompt to turn Bluetooth on (iOS 11ish?), if it was fully or partially off. – O'Rooney Sep 13 '22 at 23:05

1 Answers1

0

I guess that I can infer the default behaviour is:

  • Ask for permission to use Bluetooth, the first time. In iOS15 the prompt says "App Name" Would Like to Use Bluetooth, followed by the usage reason from your info.plist [Don't Allow] [OK]
  • If Bluetooth is fully off in Settings, prompt "Turn on Bluetooth to Allow "App name" to Connect to Accessories" [Settings] [Close]
  • If Bluetooth is disabled in control panel (aka not allowing new connections), prompt ""App Name" would like to use Bluetooth for new connections. You can allow new connections in Settings [Settings] [Close]

There is suposedly an option to control whether the second two prompts happen, but it doesn't currently work in my testing (iOS15.5)

O'Rooney
  • 2,878
  • 2
  • 27
  • 41