From d95a359719142ef4a2a79596fc6b8cdf1d206bed Mon Sep 17 00:00:00 2001 From: Don Coleman Date: Fri, 13 Jul 2018 11:06:17 -0400 Subject: [PATCH] fix(ble): change signature for autoConnect (#2594) * fix(ble): change signature for autoConnect (#2573) * fix(ble): update usage for autoConnect (#2573) --- src/@ionic-native/plugins/ble/index.ts | 37 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/@ionic-native/plugins/ble/index.ts b/src/@ionic-native/plugins/ble/index.ts index 9766b1f584..3fcd7fe8de 100644 --- a/src/@ionic-native/plugins/ble/index.ts +++ b/src/@ionic-native/plugins/ble/index.ts @@ -290,25 +290,34 @@ export class BLE extends IonicNativePlugin { } /** - * Establish an automatic connection to a peripheral. + * Establish an automatic connection to a peripheral. The phone will automatically connect to the Bluetooth peripheral + * whenever it is in range. The autoConnect function uses callbacks instead of observables because connect and + * disconnect can each be called many times as a devices connects and disconnects. + * + * On Android you can pass a MAC address directly to autoConnect. With iOS, you need to get a device id by scanning, + * calling ble.peripheralsWithIdentifiers, or calling ble.connectedPeripheralsWithServices. + * * @usage * ``` - * BLE.autoConnect('12:34:56:78:9A:BC').subscribe(peripheralData => { - * console.log(peripheralData); - * }, - * peripheralData => { - * console.log('disconnected'); - * }); + * someFunction() { + * this.ble.autoConnect(deviceId, onConnected.bind(this), onDisconnected.bind(this)); + * } + * + * onConnected(peripheral) { + * console.log(`Connected to ${peripheral.id}`)l + * } + * + * onDisconnected(peripheral) { + * console.log(`Disconnected from ${peripheral.id}`)l + * } + * * ``` * @param {string} deviceId UUID or MAC address of the peripheral - * @return {Observable} Returns an Observable that notifies of connect/disconnect. + * @param {function} connectCallback function that is called with peripheral data when the devices connects + * @param {function} disconnectCallback function that is called with peripheral data when the devices disconnects */ - @Cordova({ - observable: true, - clearFunction: 'disconnect', - clearWithArgs: true - }) - autoConnect(deviceId: string): Observable { + @Cordova({ sync: true }) + autoConnect(deviceId: string, connectCallback: any, disconnectCallback: any) { return; }