You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-native-bluetooth-state-manager/README.md
+80-63Lines changed: 80 additions & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@
4
4
5
5
The only purpose of this library is to manage the Bluetooth state. Not more, not less.
6
6
7
-
If you need further functionality like connecting and communicating to a device, please look at [react-native-ble-plx](https://github.com/Polidea/react-native-ble-plx).
7
+
If you need further functionality like connecting and communicating with a device, please look at [react-native-ble-plx](https://github.com/Polidea/react-native-ble-plx).
8
8
9
-
## Table Of Content
9
+
## Table Of Contents
10
10
11
11
-[Installation](#installation)
12
12
-[Setup](#setup)
@@ -15,6 +15,8 @@ If you need further functionality like connecting and communicating to a device,
15
15
16
16
## Installation
17
17
18
+
Requires react-native `>=0.75`. See also the requirements of [react-native-nitro-modules](https://nitro.margelo.com/docs/minimum-requirements).
19
+
18
20
```shell
19
21
bun add react-native-nitro-modules react-native-bluetooth-state-manager
You must provide a short description why you need access to bluetooth in your app. Otherwise your app will crash when requesting for bluetooth:
35
+
You must provide a short description of why you need access to Bluetooth in your app. Otherwise, your app will crash when requesting Bluetooth access:
34
36
35
37
```
36
38
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSBluetoothAlwaysUsageDescription key with a string value explaining to the user how the app uses this data.
`BLUETOOTH_CONNECT` is a runtime permission, that means you must ask the user at runtime for permission. For that, we recommend [react-native-permissions](https://github.com/zoontek/react-native-permissions/tree/master).
67
+
`BLUETOOTH_CONNECT` is a runtime permission, which means you must ask the user at runtime for permission. For that, we recommend [react-native-permissions](https://github.com/zoontek/react-native-permissions/tree/master).
|[useBluetoothState(enabled: boolean = true)](#usebluetoothstate)|`BluetoothState`| Android, iOS | Hook that returns the current state of the bluetooth service. |
114
+
|[getState()](#getstate)|`Promise<BluetoothState>`| Android, iOS | Returns the current state of the bluetooth service. |
115
+
|[getStateSync()](#getstatesync)|`BluetoothState`| Android, iOS | Returns the current state synchronous of the bluetooth service. |
116
+
|[addListener(listener, emitCurrentState)](#addlistener)|`Subscription`| Android, iOS | Listen for bluetooth state changes. |
117
+
|[openSettings()](#opensettings)|`Promise<null>`| Android, iOS | Opens the bluetooth settings. Please see below for more details. |
118
+
|[requestToEnable()](#requesttoenable)|`Promise<void>`| Android | Show a dialog that allows the user to turn on Bluetooth. |
119
+
|[requestToDisable()](#requesttodisable)|`Promise<void>`| Android | Show a dialog that allows the user to turn off Bluetooth. |
104
120
105
121
---
106
122
107
-
### useBluetoothState()
123
+
### useBluetoothState(enabled: boolean = true)
108
124
109
125
Hook that returns the current state of the bluetooth service.
Opens the settings page of the app. Please see [here](https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring).
191
208
192
209
```tsx
193
-
BluetoothStateManager.openSettings()
210
+
BluetoothStateManager.openSettings();
194
211
```
195
212
196
213
### requestToEnable()
197
214
198
215
Show a dialog that allows the user to turn on Bluetooth. More here: [Android documentation](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_REQUEST_ENABLE).
199
216
200
-
- This function is **only** on **android** available.
217
+
- This function is **only**available on **Android**.
201
218
202
219
```tsx
203
220
try {
204
-
awaitBluetoothStateManager.requestToEnable()
221
+
awaitBluetoothStateManager.requestToEnable();
205
222
} catch (error) {
206
223
// Failed
207
224
}
@@ -211,19 +228,19 @@ try {
211
228
212
229
Show a dialog that allows the user to turn off Bluetooth.
213
230
214
-
- This function is **only** on **android** available.
231
+
- This function is **only**available on **Android**.
215
232
216
233
```tsx
217
234
try {
218
-
awaitBluetoothStateManager.requestToDisable()
235
+
awaitBluetoothStateManager.requestToDisable();
219
236
} catch (error) {
220
237
// Failed
221
238
}
222
239
```
223
240
224
241
## Why?
225
242
226
-
##### Why not just using[react-native-ble-plx](https://github.com/Polidea/react-native-ble-plx)?
243
+
##### Why not just use[react-native-ble-plx](https://github.com/Polidea/react-native-ble-plx)?
0 commit comments