How to hide the Bluetooth Alert in Swift
If an app tries to use Bluetooth and Bluetooth is turned off or permissions are denied, a pop-up will appear prompting the user to allow Bluetooth in Settings.
To stop the alert from appearing, initialize the CBCentralManager with options that include the CBCentralManagerOptionShowPowerAlertKey set to false.
The Problem
As of October 2023, Apple does not provide a way to determine if a user has granted Bluetooth permissions to an app or if Bluetooth is turned on, on a device.
In order to determine the Bluetooth status, a Swift app (i.e. iOS, iPadOS, MacOS, TVOS, WatchOS, VisionOS) must create a CBCentralManager and consult its state using the centralManagerDidUpdateState delegate function.
In the event that Bluetooth is not authorized or it is not powered on, the user will experience the alert shown below.
The Solution
To stop the pop up from appearing, you must initialize the CBCentralManager with options that include the CBCentralManagerOptionShowPowerAlertKey set to false.
let centralManager: CBCentralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: false]);