In order to actually instantiate Core Bluetooth managers, we need to make sure that our apps are ready for it.
There’s an important info.plist
key that needs to be set, and, for the Mac, we also need to check a box.
The Bluetooth Privacy Key
Apple has implemented strict standards for apps that need to be released through the App Store, including privacy and system resource access restrictions. As of the latest operating systems, we won’t be able to run an app on-device –even in debug mode– without setting a particular key in the info.plist
file.
The key is NSBluetoothAlwaysUsageDescription
. In the “Info” section of the project’s Target Navigator, it will be displayed as “Privacy – Bluetooth Always Usage Description,” or “Privacy – Bluetooth Peripheral Usage Description” (which is actually a legacy key).
The payload should be a String, describing the usage. In the companion apps to this series, I use the String “The App Needs to Connect to Bluetooth Devices”. Pretty boring, but gets the point across. This string will be displayed in the permission alert, and tells the user why they should hit the “OK” button, instead of the “Don’t Allow” button (If we don’t hit “OK,” then the lesson is done. We won’t be able to run Bluetooth on our device).
MacOS App Sandbox Key
On the Mac, we have an additional step that needs to happen in the App Sandbox section of the Target’s “Signing & Capabilities” tab:
Provisioning Certificates
We also need to have signing certificates ready. These will be necessary to run our apps on devices.
The provisioning system is a constantly-changing environment. It’s fairly non-trivial, and is beyond the scope of this lesson. Apple discusses it here. There is also some discussion of synchronizing with the App Store.
We’ll need to edit the “Signing & Capabilities” section of each of the companion apps, and replace the one I set with whatever one we have created.
Once that’s done, we’ll be able to start bringing in true Bluetooth code, as we can only test that on-device. The simulators will not support Bluetooth.
Now that the preliminaries are set up, let’s get to coding.