-
Notifications
You must be signed in to change notification settings - Fork 544
Bluetooth Scanning
Dariusz Seweryn edited this page May 3, 2020
·
3 revisions
react-native-ble-plx supports scanning of BLE peripherals.
To perform a scan one must use:
bleManager.startDeviceScan(
UUIDs: ?Array<UUID>,
options: ?ScanOptions,
listener: (error: ?Error, scannedDevice: ?Device) => void
)
-
UUIDs—Array of strings containingUUIDs ofServices which are registered in scannedDevice. Ifnullis passed, all availableDevices will be scanned. -
ScanOptions—Optional configuration for scanning operation.-
allowDuplicates?: boolean—duplicate scanning records are received more frequently [iOS only—defaultfalse]. On Android the duplicates will be emitted.
-
-
listener—Function which will be called for every scannedDevice(devices may be scanned multiple times). It's first argument is potentialErrorwhich is set to nonnullvalue when scanning failed. You have to start scanning process again if that happens. Second argument is a scannedDevice
When the scan is no longer needed one must call:
bleManager.stopDeviceScan()
- iOS:
- Background scanning—one must provide a non-empty
UUIDsarray and be aware of how the app behaviour will change.
- Background scanning—one must provide a non-empty
- Android:
- Since Android 6 to scan the app needs to have
ACCESS_COARSE_LOCATIONorACCESS_FINE_LOCATIONruntime permission. Since Android 10 onlyACCESS_FINE_LOCATIONis accepted by the OS. - Background scanning—the OS may kill the application on arbitrary moment once in the background. There are native ways of waking/keeping the app. Since Android 10 to scan in background an additional runtime permission is needed:
ACCESS_BACKGROUND_LOCATION - Performing other BLE actions while scan is active may cause problems on some devices.
- Since Android 6 to scan the app needs to have