Skip to content

Commit d95a359

Browse files
dondanielsogl
authored andcommitted
fix(ble): change signature for autoConnect (#2594)
* fix(ble): change signature for autoConnect (#2573) * fix(ble): update usage for autoConnect (#2573)
1 parent 12ddf96 commit d95a359

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/@ionic-native/plugins/ble/index.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -290,25 +290,34 @@ export class BLE extends IonicNativePlugin {
290290
}
291291

292292
/**
293-
* Establish an automatic connection to a peripheral.
293+
* Establish an automatic connection to a peripheral. The phone will automatically connect to the Bluetooth peripheral
294+
* whenever it is in range. The autoConnect function uses callbacks instead of observables because connect and
295+
* disconnect can each be called many times as a devices connects and disconnects.
296+
*
297+
* On Android you can pass a MAC address directly to autoConnect. With iOS, you need to get a device id by scanning,
298+
* calling ble.peripheralsWithIdentifiers, or calling ble.connectedPeripheralsWithServices.
299+
*
294300
* @usage
295301
* ```
296-
* BLE.autoConnect('12:34:56:78:9A:BC').subscribe(peripheralData => {
297-
* console.log(peripheralData);
298-
* },
299-
* peripheralData => {
300-
* console.log('disconnected');
301-
* });
302+
* someFunction() {
303+
* this.ble.autoConnect(deviceId, onConnected.bind(this), onDisconnected.bind(this));
304+
* }
305+
*
306+
* onConnected(peripheral) {
307+
* console.log(`Connected to ${peripheral.id}`)l
308+
* }
309+
*
310+
* onDisconnected(peripheral) {
311+
* console.log(`Disconnected from ${peripheral.id}`)l
312+
* }
313+
*
302314
* ```
303315
* @param {string} deviceId UUID or MAC address of the peripheral
304-
* @return {Observable<any>} Returns an Observable that notifies of connect/disconnect.
316+
* @param {function} connectCallback function that is called with peripheral data when the devices connects
317+
* @param {function} disconnectCallback function that is called with peripheral data when the devices disconnects
305318
*/
306-
@Cordova({
307-
observable: true,
308-
clearFunction: 'disconnect',
309-
clearWithArgs: true
310-
})
311-
autoConnect(deviceId: string): Observable<any> {
319+
@Cordova({ sync: true })
320+
autoConnect(deviceId: string, connectCallback: any, disconnectCallback: any) {
312321
return;
313322
}
314323

0 commit comments

Comments
 (0)