问题描述
如在ILE 2的BLE的git中所提到的,我们可以注册BLE启用或禁用状态:。但它给了我错误属性 startStateNotification
在BLE类型上不存在。我的代码是:
As mentioned in git of BLE for IONIC 2 we can register for BLE enable or disable state : https://github.com/don/cordova-plugin-ble-central#startstatenotifications . But It gives me error Property startStateNotification
does not exist on type of BLE. My code is :
ble.startStateNotifications(
function(state) {
console.log("Bluetooth is " + state);
});
我在这里缺少什么。我想要成功并且还要回避两个回调。请提供解决方案..
What I am missing here.I want success and failer both callbacks as well. Please provide solution..
推荐答案
您正在通过
从离子本地
导入{ble}是吗?
import {ble} from ionic-native
is it?
如果你看一下离子文件-native> dist> plugins> ble.js,提供了一个命令列表。检查是否有名为 startStateNotifications
的命令。
If you take a look at the files in ionic-native>dist>plugins>ble.js, there are a list of commands provided. Check if there is a command called startStateNotifications
.
这很可能意味着ble没有这个功能。
This would most likely mean ble does not have this function.
您必须检查 ionic-native
是否使用最新版本的 cordova-plugin-ble-central
。
You have to check if ionic-native
is using the latest version of cordova-plugin-ble-central
.
更新
您可以通过在命令提示符中运行此命令来导入插件,而不是通过ionic-native导入:
Instead of importing through ionic-native, you can import the plugin by running this command in command prompt:
cordova插件添加cordova-plugin-ble -central
之后,您将使用它作为插件。所以只需调用 ble.startStateNotification()
您不需要在ionic-native 中包含 import {ble}。
Afterwards, you will use this as a plugin. So just call ble.startStateNotification()
You will not need to include import {ble} from ionic-native
already.
我更喜欢直接从主作者导入 cordova-plugin-ble-central
而不是通过 ionic-native
调用 cordova-plugin-ble-central
。如果插件有任何更新,您可以立即更新。否则,你将不得不等待 ionic-native
I prefer directly importing cordova-plugin-ble-central
from the main author instead of going through ionic-native
to call cordova-plugin-ble-central
. In the event of any updates from the plugin, you can update immediately. Else, you will have to wait on ionic-native
这篇关于如何在IONIC 2中注册BLE状态通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!