@@ -290,25 +290,34 @@ export class BLE extends IonicNativePlugin {
290
290
}
291
291
292
292
/**
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
+ *
294
300
* @usage
295
301
* ```
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
+ *
302
314
* ```
303
315
* @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
305
318
*/
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 ) {
312
321
return ;
313
322
}
314
323
0 commit comments