nativescript-bluetooth не показывает устройство - PullRequest
0 голосов
/ 25 июня 2018

Я новый разработчик мобильных приложений. Я работаю с Nativescript. Я хочу создать функцию blouetooth для поиска устройства и связи с устройством. Я попробовал этот код:

код Ц:

import { Component, OnInit, NgZone } from "@angular/core";

let ble = require("nativescript-bluetooth");
   export class ItemsComponent implements OnInit {
    log: string = "";
    constructor(private zone: NgZone) { }
    ngOnInit(): void {
    }
    startScanning() {
        console.log(ble.startScanning)
           ble.startScanning({
            serviceUUIDs: [],
            seconds: 5,
            onDiscovered: (peripheral) => {
                console.log('peripheral.name')
                console.log(peripheral.name)
                this.zone.run(() => {
                    this.updateLog(`Device Name: ${peripheral.name}`);
                  })
                if (peripheral.name == "SWING") {
                    this.stopScanning();
                    this.updateLog(`Device Name: ${peripheral.name}`);
                }
            }
        }).then(() => {
            this.updateLog("scanning completed");
        }, (err) => {
            console.error(`Error on scanning: ${err}`);
        })
    }
        stopScanning() {
        ble.stopScanning().then(() => {
            this.updateLog("Stopped");
        })
    }
        updateLog(message) {
        console.log(message);
        this.log += `\n${message}`;
    }
}

HTML-код:

<ActionBar title="My App" class="action-bar">
</ActionBar>
     <StackLayout>
        <Button class="btn btn-primary btn-active" id="appButton" text="Search Device" (tap)="startScanning()"></Button>

        <TextView text="{{ log }}" style="height: 100%;background-color: #282a37;color: #fff;" editable="false"></TextView>
    </StackLayout> 

Результат:

console.log (ble.startScanning)

> JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode. JS: function (arg) { 
> JS: return new Promise(function (resolve, reject) { 
> JS: try { 
> JS: if (!Bluetooth._isEnabled())...<omitted>... 
> JS: }
...