-
Notifications
You must be signed in to change notification settings - Fork 516
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 containingUUID
s ofService
s which are registered in scannedDevice
. Ifnull
is passed, all availableDevice
s 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 potentialError
which is set to nonnull
value 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
UUIDs
array 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_LOCATION
orACCESS_FINE_LOCATION
runtime permission. Since Android 10 onlyACCESS_FINE_LOCATION
is 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