【iOS】Bluetooth Background Usage Permissions
1. Problem Description
Sometimes, we receive feedback from customers who encounter issues while using their developed applications. Specifically, when the app is switched to run in the background, although the Bluetooth device remains connected with the app, the device's DP (Data Points) and related information cannot sync properly.
The core of this issue lies in the proper configuration of a very important permission in the Bluetooth communication process — the "Uses Bluetooth LE accessories" permission.
2. Permission Overview
For iOS apps, it is crucial to know whether your app is running in the foreground or the background. An app must behave differently in the background than in the foreground, because system resources are more limited on iOS devices. For an overall discussion of background operation on iOS, see Background Execution in App Programming Guide for iOS.
By default, many of the common Core Bluetooth tasks—on both the central and peripheral side—are disabled while your app is in the background or in a suspended state. That said, you can declare your app to support the Core Bluetooth background execution modes to allow your app to be woken up from a suspended state to process certain Bluetooth-related events. Even if your app doesn’t need the full range of background processing support, it can still ask to be alerted by the system when important events occur.
Even if your app supports one or both of the Core Bluetooth background execution modes, it can’t run forever. At some point, the system may need to terminate your app to free up memory for the current foreground app—causing any active or pending connections to be lost, for instance. As of iOS 7, Core Bluetooth supports saving state information for central and peripheral manager objects and restoring that state at app launch time. You can use this feature to support long-term actions involving Bluetooth devices. (Translated from Apple Doc.)
3. Permission Configuration
3.1 SDK Developers
Step 1: In your project, enable the "Use Bluetooth LE accessories" option.
Step 2: Configure the necessary declarations in the
Info.plist
.
3.2 OEM App Customers
Currently, the OEM app has this permission disabled by default. If you need to enable this permission, you must contact your Tuya customer manager or FAE to unlock this feature.