Android上的BLE扫描不适用于Ionic4(4.12.0)简单测试应用程序。没有错误消息,启用检查又回来了。订阅永不返回。请参阅下面的logcat。任何帮助都非常感谢。
这是从头开始重现问题的方法:
ionic start BLEscanner blank
cd BLEscanner/
cordova plugin add cordova-plugin-ble-central --variable BLUETOOTH_USAGE_DESCRIPTION="Scan for mesh packets"
npm install --save @ionic-native/ble
ionic cordova platform add android@8.0.0 (tried with 7.1.0 and 6.4.0)
ionic cordova plugin add cordova-plugin-ionic-webview@latest
用以下代码替换home.page.ts:
import { OnInit, Component } from '@angular/core';
import { BLE } from '@ionic-native/ble/ngx';
import {
Platform,
} from '@ionic/angular';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
constructor(
private ble: BLE,
private platform: Platform,
){
console.log("constructor home page");
}
async ngOnInit() {
// Since ngOnInit() is executed before `deviceready` event,
// you have to wait the event.
await this.platform.ready();
console.log(`enter view, start scanning`)
this.ble.scan([], 5).subscribe(
device =>
console.log(JSON.stringify(device))),
error => console.log(`error ${error}`);
}
}
编译并运行:
ionic cordova run android --device
检查chrome:// inspect /#devices进行检查并查看控制台。 您得到的是:
Angular is running in the development mode. Call enableProdMode() to enable the production mode.
cordova.js:1218 deviceready has not fired after 5 seconds.
vendor.js:74395 Ionic Native: deviceready event fired after 3303 ms
home-home-module.js:98 constructor home page
home-home-module.js:135 enter view, start scanning
没有扫描结果。是的,目前有很多BLE广告客户。是的,该应用具有位置权限。
android logcat中的错误消息是:
05-03 15:30:42.368 17937 20508 I Places : ?: PlacesBleScanner stop()
05-03 15:30:42.394 17937 17937 I BeaconBle: 'L' hardware scan: scan stopped, no clients
05-03 15:30:42.394 17937 17937 I BeaconBle: Scan canceled successfully.
知道发生了什么事。奇怪的事情,这以前工作。一些版本不匹配?
答案 0 :(得分:0)
答案是:离子版本不匹配。 如果@ ionic-native / core和@ ionic-native / ble不同,它将停止工作
这有效:
"@ionic-native/ble": "^5.5.1",
"@ionic-native/core": "^5.5.1",