Skip to content

Commit c7d4d3e

Browse files
committed
test: demo fixes
1 parent cdc5cd8 commit c7d4d3e

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

demo-ng/app/services/bluetooth.service.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core';
22
import { Observable, Subscription, fromEventPattern } from 'rxjs';
33
import { takeWhile } from 'rxjs/operators';
44
import * as dialogs from '@nativescript/core/ui/dialogs';
5-
import { Bluetooth, Peripheral, Service, Characteristic, ReadResult } from '@nativescript-community/ble';
5+
import { Bluetooth, Characteristic, Peripheral, ReadResult, Service } from '@nativescript-community/ble';
66

77
const bluetooth = new Bluetooth();
88
bluetooth.debug = true;
@@ -85,7 +85,7 @@ export class BluetoothService {
8585
console.log('Creating BluetoothService');
8686
}
8787

88-
public peripheralList: Array<IPeripheral> = []; // public storage for the list of last-scanned peripherals
88+
public peripheralList: IPeripheral[] = []; // public storage for the list of last-scanned peripherals
8989
public isScanning = false;
9090

9191
private isBluetoothEnabled: boolean;
@@ -215,9 +215,9 @@ export class BluetoothService {
215215
console.log(`scanForPeripherals(${JSON.stringify(serviceUUIDs)}, ${seconds}) called`);
216216

217217
// Android 6 needs this permission to scan for peripherals in the background.
218-
bluetooth.hasCoarseLocationPermission().then(granted => {
218+
bluetooth.hasLocationPermission().then(granted => {
219219
if (!granted) {
220-
bluetooth.requestCoarseLocationPermission();
220+
bluetooth.requestLocationPermission();
221221
return false;
222222
}
223223
});
@@ -227,9 +227,7 @@ export class BluetoothService {
227227
this.scanSubscription = this.startScan(serviceUUIDs, seconds)
228228
.pipe(
229229
takeWhile(
230-
(peripheral: IPeripheral, idx: number): boolean => {
231-
return peripheral.UUID !== BluetoothService.SIGNAL_STOP_PERIPHERAL().UUID;
232-
}
230+
(peripheral: IPeripheral, idx: number): boolean => peripheral.UUID !== BluetoothService.SIGNAL_STOP_PERIPHERAL().UUID
233231
)
234232
)
235233
.subscribe(
@@ -259,7 +257,7 @@ export class BluetoothService {
259257
bluetooth
260258
.startScanning({
261259
filters,
262-
seconds: seconds,
260+
seconds,
263261
onDiscovered: (peripheral: IPeripheral) => handler(peripheral),
264262
skipPermissionCheck: false
265263
})
@@ -380,7 +378,7 @@ export class BluetoothService {
380378
peripheralUUID: characteristic.serviceRef.peripheralRef.UUID,
381379
serviceUUID: characteristic.serviceRef.UUID,
382380
characteristicUUID: characteristic.UUID,
383-
value: value
381+
value
384382
})
385383
.then(
386384
res => {
@@ -425,7 +423,7 @@ export class BluetoothService {
425423
peripheralUUID: characteristic.serviceRef.peripheralRef.UUID,
426424
serviceUUID: characteristic.serviceRef.UUID,
427425
characteristicUUID: characteristic.UUID,
428-
value: value
426+
value
429427
})
430428
.then(
431429
res => {

demo/app/main-view-model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Observable } from '@nativescript/core/data/observable';
33
import { ObservableArray } from '@nativescript/core/data/observable-array';
44
import { topmost } from '@nativescript/core/ui/frame';
55
import { Prop } from './utils/obs-prop';
6-
import { Bluetooth, getBluetoothInstance, Peripheral } from '@nativescript-community/ble';
6+
import { Bluetooth, Peripheral, getBluetoothInstance } from '@nativescript-community/ble';
77

88
export class DemoAppModel extends Observable {
99
@Prop() public isLoading = false;
@@ -92,9 +92,9 @@ export class DemoAppModel extends Observable {
9292

9393
// this one 'manually' checks for permissions
9494
public doScanForHeartrateMontitor() {
95-
this._bluetooth.hasCoarseLocationPermission().then(granted => {
95+
this._bluetooth.hasLocationPermission().then(granted => {
9696
if (!granted) {
97-
this._bluetooth.requestCoarseLocationPermission().then(
97+
this._bluetooth.requestLocationPermission().then(
9898
// doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below
9999
granted2 => {
100100
dialogs.alert({
@@ -141,7 +141,7 @@ export class DemoAppModel extends Observable {
141141

142142
// this one 'manually' checks for permissions
143143
public doScanForBeacon() {
144-
this._bluetooth.hasCoarseLocationPermission().then(granted => {
144+
this._bluetooth.hasLocationPermission().then(granted => {
145145
if (!granted) {
146146
this._bluetooth.requestCoarseLocationPermission().then(
147147
// doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below

0 commit comments

Comments
 (0)