@@ -27,7 +27,7 @@ cd ios && bunx pod-install
27
27
## Setup
28
28
29
29
``` tsx
30
- import { BluetoothStateManager } from " react-native-bluetooth-state-manager" ;
30
+ import { BluetoothStateManager } from ' react-native-bluetooth-state-manager'
31
31
```
32
32
33
33
** iOS**
@@ -73,35 +73,35 @@ import {
73
73
useBluetoothState ,
74
74
BluetoothStateManager ,
75
75
BluetoothState ,
76
- } from " react-native-bluetooth-state-manager" ;
76
+ } from ' react-native-bluetooth-state-manager'
77
77
78
78
// Get bluetooth state
79
79
80
80
// hook
81
- const bluetoothState = useBluetoothState ();
81
+ const bluetoothState = useBluetoothState ()
82
82
// synchronous
83
- const bluetoothState = BluetoothStateManager .getStateSync ();
83
+ const bluetoothState = BluetoothStateManager .getStateSync ()
84
84
// asynchronous
85
- const bluetoothState = await BluetoothStateManager .getState ();
85
+ const bluetoothState = await BluetoothStateManager .getState ()
86
86
// Event listener
87
- const [bluetoothState, setBluetoothState] = useState <BluetoothState >();
87
+ const [bluetoothState, setBluetoothState] = useState <BluetoothState >()
88
88
useEffect (() => {
89
89
const remove = BluetoothStateManager .addListener ((state ) => {
90
- setBluetoothState (state );
91
- });
92
- return remove ;
93
- }, []);
90
+ setBluetoothState (state )
91
+ })
92
+ return remove
93
+ }, [])
94
94
95
95
// Open settings page
96
- await BluetoothStateManager .openSettings ();
96
+ await BluetoothStateManager .openSettings ()
97
97
98
98
// Android only
99
99
100
100
// Ask user to enable bluetooth
101
- await BluetoothStateManager .requestToEnable ();
101
+ await BluetoothStateManager .requestToEnable ()
102
102
103
103
// Ask user to disable bluetooth
104
- await BluetoothStateManager .requestToDisable ();
104
+ await BluetoothStateManager .requestToDisable ()
105
105
```
106
106
107
107
## API
@@ -125,19 +125,19 @@ An example is under `example/App.tsx`
125
125
Hook that returns the current state of the bluetooth service.
126
126
127
127
``` tsx
128
- import { useBluetoothState } from " react-native-bluetooth-state-manager" ;
128
+ import { useBluetoothState } from ' react-native-bluetooth-state-manager'
129
129
130
- const enabled = true ; // default true
131
- const bluetoothState = useBluetoothState (enabled );
130
+ const enabled = true // default true
131
+ const bluetoothState = useBluetoothState (enabled )
132
132
switch (bluetoothState ) {
133
- case " Unknown" :
134
- case " Resetting" :
135
- case " Unsupported" :
136
- case " Unauthorized" :
137
- case " PoweredOff" :
138
- case " PoweredOn" :
133
+ case ' Unknown' :
134
+ case ' Resetting' :
135
+ case ' Unsupported' :
136
+ case ' Unauthorized' :
137
+ case ' PoweredOff' :
138
+ case ' PoweredOn' :
139
139
default :
140
- break ;
140
+ break
141
141
}
142
142
```
143
143
@@ -146,17 +146,17 @@ switch (bluetoothState) {
146
146
Returns the current state of the bluetooth service.
147
147
148
148
``` tsx
149
- import { BluetoothStateManager } from " react-native-bluetooth-state-manager" ;
150
- const bluetoothState = await BluetoothStateManager .getState ();
149
+ import { BluetoothStateManager } from ' react-native-bluetooth-state-manager'
150
+ const bluetoothState = await BluetoothStateManager .getState ()
151
151
switch (bluetoothState ) {
152
- case " Unknown" :
153
- case " Resetting" :
154
- case " Unsupported" :
155
- case " Unauthorized" :
156
- case " PoweredOff" :
157
- case " PoweredOn" :
152
+ case ' Unknown' :
153
+ case ' Resetting' :
154
+ case ' Unsupported' :
155
+ case ' Unauthorized' :
156
+ case ' PoweredOff' :
157
+ case ' PoweredOn' :
158
158
default :
159
- break ;
159
+ break
160
160
}
161
161
```
162
162
@@ -165,17 +165,17 @@ switch (bluetoothState) {
165
165
Returns the current state synchronous of the bluetooth service.
166
166
167
167
``` tsx
168
- import { BluetoothStateManager } from " react-native-bluetooth-state-manager" ;
169
- const bluetoothState = BluetoothStateManager .getStateSync ();
168
+ import { BluetoothStateManager } from ' react-native-bluetooth-state-manager'
169
+ const bluetoothState = BluetoothStateManager .getStateSync ()
170
170
switch (bluetoothState ) {
171
- case " Unknown" :
172
- case " Resetting" :
173
- case " Unsupported" :
174
- case " Unauthorized" :
175
- case " PoweredOff" :
176
- case " PoweredOn" :
171
+ case ' Unknown' :
172
+ case ' Resetting' :
173
+ case ' Unsupported' :
174
+ case ' Unauthorized' :
175
+ case ' PoweredOff' :
176
+ case ' PoweredOn' :
177
177
default :
178
- break ;
178
+ break
179
179
}
180
180
```
181
181
@@ -184,10 +184,10 @@ switch (bluetoothState) {
184
184
Listen for bluetooth state changes.
185
185
186
186
``` tsx
187
- import { BluetoothStateManager } from " react-native-bluetooth-state-manager" ;
187
+ import { BluetoothStateManager } from ' react-native-bluetooth-state-manager'
188
188
BluetoothStateManager .addListener ((bluetoothState ) => {
189
189
// do something...
190
- }, true /* =emitCurrentState*/ );
190
+ }, true /* =emitCurrentState*/ )
191
191
```
192
192
193
193
### openSettings()
@@ -207,7 +207,7 @@ Tested:
207
207
Opens the settings page of the app. Please see [ here] ( https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring ) .
208
208
209
209
``` tsx
210
- BluetoothStateManager .openSettings ();
210
+ BluetoothStateManager .openSettings ()
211
211
```
212
212
213
213
### requestToEnable()
@@ -218,7 +218,7 @@ Show a dialog that allows the user to turn on Bluetooth. More here: [Android doc
218
218
219
219
``` tsx
220
220
try {
221
- await BluetoothStateManager .requestToEnable ();
221
+ await BluetoothStateManager .requestToEnable ()
222
222
} catch (error ) {
223
223
// Failed
224
224
}
@@ -232,7 +232,7 @@ Show a dialog that allows the user to turn off Bluetooth.
232
232
233
233
``` tsx
234
234
try {
235
- await BluetoothStateManager .requestToDisable ();
235
+ await BluetoothStateManager .requestToDisable ()
236
236
} catch (error ) {
237
237
// Failed
238
238
}
0 commit comments