问题
The question could be duplicated, but I have tried a lot of code and it wasn't work. I have read about
CBCentralManagerOptionShowPowerAlertKey
option and the possibility to show an alert to go settings bluetooth option into iPhone for turn on on the application, but I haven't get works this.
If I set the key to true the key not appear, and when I change the value to false the key not works...
I'm using this code into my Swift application:
var bCentralManger: CBCentralManager!
self.bCentralManger = CBCentralManager(delegate: self, queue: DispatchQueue.main, options: [CBCentralManagerOptionShowPowerAlertKey: true])
Works this option in iOS? I'm using iOS 12 on my device. Have anybody this code working? Thanks!
回答1:
The Bluetooth power alert is only shown if Bluetooth is turned off from the Settings app. If you simply disable Bluetooth from the control center, then the dialog is not shown. Disabling Bluetooth from the control center disconnects any connected peripherals but does not completely power off the Bluetooth hardware.
You can display your own alert in response to a .poweredOff
state in the centralManagerDidUpdateState
delegate method. Unfortunately you cannot send the user directly to the Bluetooth settings in this case.
You could log a Radar with Apple regarding this behaviour, but I suspect that they will respond that the system is working as intended.
来源:https://stackoverflow.com/questions/55212803/how-to-show-an-alert-when-turn-off-bluetooth-in-swift-app