Cordova BLE Central 插件使用教程

Cordova BLE Central 插件使用教程

cordova-plugin-ble-centralBluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)项目地址:https://gitcode.com/gh_mirrors/co/cordova-plugin-ble-central

1. 项目的目录结构及介绍

cordova-plugin-ble-central/
├── src/
│   ├── android/
│   │   └── BLECentralPlugin.java
│   ├── ios/
│   │   └── BLECentralPlugin.m
│   └── windows/
│       └── BLECentralPlugin.cs
├── www/
│   └── ble.js
├── package.json
├── plugin.xml
└── README.md
  • src/: 包含插件的平台特定源代码。
    • android/: Android 平台的源代码。
    • ios/: iOS 平台的源代码。
    • windows/: Windows 平台的源代码。
  • www/: 包含插件的 JavaScript 接口。
  • package.json: 插件的 npm 包信息。
  • plugin.xml: 插件的配置文件。
  • README.md: 插件的说明文档。

2. 项目的启动文件介绍

插件的启动文件主要是 www/ble.js,它定义了插件的 JavaScript 接口,包括扫描、连接、读写等 BLE 操作。

var exec = require('cordova/exec');

var BLECentralPlugin = {
    scan: function(services, seconds, success, failure) {
        exec(success, failure, "BLECentralPlugin", "scan", [services, seconds]);
    },
    connect: function(device_id, success, failure) {
        exec(success, failure, "BLECentralPlugin", "connect", [device_id]);
    },
    // 其他方法...
};

module.exports = BLECentralPlugin;

3. 项目的配置文件介绍

plugin.xml 是插件的配置文件,它定义了插件的名称、版本、依赖关系以及各个平台的具体配置。

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
    id="cordova-plugin-ble-central"
    version="1.4.0">
    <name>BLE Central</name>
    <js-module name="ble" src="www/ble.js">
        <clobbers target="ble" />
    </js-module>
    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="BLECentralPlugin">
                <param name="android-package" value="com.megster.cordova.ble.central.BLECentralPlugin"/>
            </feature>
        </config-file>
        <source-file src="src/android/BLECentralPlugin.java" target-dir="src/com/megster/cordova/ble/central"/>
    </platform>
    <platform name="ios">
        <config-file target="config.xml" parent="/*">
            <feature name="BLECentralPlugin">
                <param name="ios-package" value="BLECentralPlugin"/>
            </feature>
        </config-file>
        <source-file src="src/ios/BLECentralPlugin.m" />
    </platform>
    <platform name="windows">
        <config-file target="config.xml" parent="/*">
            <feature name="BLECentralPlugin">
                <param name="windows-package" value="BLECentralPlugin"/>
            </feature>
        </config-file>
        <source-file src="src/windows/BLECentralPlugin.cs" />
    </platform>
</plugin>

这个配置文件指定了插件的名称、版本,以及各个平台的源文件和配置信息。

cordova-plugin-ble-centralBluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)项目地址:https://gitcode.com/gh_mirrors/co/cordova-plugin-ble-central

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邴坤鸿Jewel

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值