Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular nativescript蓝牙不支持';t显示设备_Angular_Typescript_Bluetooth_Bluetooth Lowenergy_Nativescript - Fatal编程技术网

Angular nativescript蓝牙不支持';t显示设备

Angular nativescript蓝牙不支持';t显示设备,angular,typescript,bluetooth,bluetooth-lowenergy,nativescript,Angular,Typescript,Bluetooth,Bluetooth Lowenergy,Nativescript,我是新的移动开发者。我正在使用Nativescript。我想创建一个函数blouetooth,用于搜索设备并与设备连接。我尝试了以下代码: Ts代码: import { Component, OnInit, NgZone } from "@angular/core"; let ble = require("nativescript-bluetooth"); export class ItemsComponent implements OnInit { log: string =

我是新的移动开发者。我正在使用Nativescript。我想创建一个函数blouetooth,用于搜索设备并与设备连接。我尝试了以下代码:

Ts代码:

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正在开发模式下运行。调用enableProdMode()以启用生产模式。JS:function(arg){ >JS:返回新承诺(函数(解析、拒绝){ >JS:试试{ >JS:if(!Bluetooth._isEnabled())。。。。。。 >JS:}
您好。我也面临同样的问题。您找到解决方案了吗?您需要括号来调用方法(您的解决方案仅打印startScanning方法实现)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: }