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.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 09/30/2023 at 10:06
Last Updated on 09/30/2023 at 10:49
<p>Three flowers that represent Swift, Bluetooth and XCode side by side. Beneath them sits the text "Hide Bluetooth Power Alert."</p>

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.

SubscribeDownload Open Source project

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.

Learn more about the CBCentralManager

In the event that Bluetooth is not authorized or it is not powered on, the user will experience the alert shown below.

<p>A screenshot of an iPhone app showing the alert that appears if an app tries to access Bluetooth when permissions are denied or Bluetooth is turned off. It states "The app would like to use Bluetooth for new connections. You can allow new connections in Settings." It also offers two buttons - "Settings" and "Close." If you press the settings button, it takes you to the settings for the App, whilst pressing the close button closes the modal.</p>

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]);
Learn more about CBCentralManagerOptionShowPowerAlertKey

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe