@@ -20,6 +20,7 @@ export class DemoAppModel extends Observable {
2020 // using an event listener instead of the 'onDiscovered' callback of 'startScanning'
2121 this . _bluetooth . on ( Bluetooth . device_discovered_event , ( eventData : any ) => {
2222 const perip = eventData . data as Peripheral ;
23+ console . log ( 'Peripheral found:' , JSON . stringify ( eventData . data ) ) ;
2324 let index = - 1 ;
2425 this . peripherals . some ( ( p , i ) => {
2526 if ( p . UUID === perip . UUID ) {
@@ -28,7 +29,6 @@ export class DemoAppModel extends Observable {
2829 }
2930 return false ;
3031 } ) ;
31- console . log ( 'Peripheral found:' , JSON . stringify ( eventData . data ) , index ) ;
3232 if ( index === - 1 ) {
3333 this . peripherals . push ( perip ) ;
3434 } else {
@@ -94,6 +94,7 @@ export class DemoAppModel extends Observable {
9494 // this one 'manually' checks for permissions
9595 public doScanForHeartrateMontitor ( ) {
9696 this . _bluetooth . hasLocationPermission ( ) . then ( ( granted ) => {
97+ console . log ( 'hasLocationPermission' , granted ) ;
9798 if ( ! granted ) {
9899 this . _bluetooth . requestLocationPermission ( ) . then (
99100 // doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below
@@ -189,35 +190,36 @@ export class DemoAppModel extends Observable {
189190 } ) ;
190191 }
191192
192-
193193 // this one uses automatic permission handling
194194 public async doStartScanning ( ) {
195195 try {
196- // this._bluetooth.hasLocationPermission().then((granted) => {
197- // if (!granted) {
198196 const r = await request ( { bluetoothConnect : { } , bluetoothScan : { } } ) ;
199- // this._bluetooth.requestLocationPermission().then(
200- // // doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below
201- // (granted2) => {
202- // dialogs.alert({
203- // title: 'Granted?',
204- // message: granted2 ? 'Yep - now invoke that button again' : 'Nope',
205- // okButtonText: 'OK!'
206- // });
207- // }
208- // );
209- // } else {
210- this . isLoading = true ;
211- // reset the array
212- this . peripherals . length = 0 ;
213- await this . _bluetooth . startScanning ( {
214- seconds : 50 , // passing in seconds makes the plugin stop scanning after <seconds> seconds
215- onDiscovered : peripheral => {
216- console . log ( "peripheral discovered. Not adding it here because we're using a listener." ) ;
217- } ,
197+ console . log ( 'r' , r ) ;
198+ this . _bluetooth . hasLocationPermission ( ) . then ( async ( granted ) => {
199+ console . log ( 'granted' , granted ) ;
200+ if ( ! granted ) {
201+ this . _bluetooth . requestLocationPermission ( ) . then (
202+ // doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below
203+ ( granted2 ) => {
204+ dialogs . alert ( {
205+ title : 'Granted?' ,
206+ message : granted2 ? 'Yep - now invoke that button again' : 'Nope' ,
207+ okButtonText : 'OK!'
208+ } ) ;
209+ }
210+ ) ;
211+ } else {
212+ this . isLoading = true ;
213+ // reset the array
214+ this . peripherals . length = 0 ;
215+ await this . _bluetooth . startScanning ( {
216+ seconds : 50 , // passing in seconds makes the plugin stop scanning after <seconds> seconds
217+ onDiscovered : ( peripheral ) => {
218+ console . log ( "peripheral discovered. Not adding it here because we're using a listener." ) ;
219+ }
220+ } ) ;
221+ }
218222 } ) ;
219- // }
220- // });
221223 } catch ( error ) {
222224 dialogs . alert ( {
223225 title : 'Whoops!' ,
0 commit comments