更新记录
1.1.0(2023-07-06)
下载此版本
1.1.0 修复使用插件时的闪退问题
平台兼容性
Android |
Android CPU类型 |
iOS |
适用版本区间:5.0 - 12.0 |
armeabi-v7a:支持,arm64-v8a:支持,x86:支持 |
× |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
原生Android版说明文档
权限
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-feature android:name=\"android.hardware.bluetooth_le\" android:required=\"true\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH_CONNECT\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH_SCAN\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADVERTISE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>"
引入
const plugin = uni.requireNativePlugin('plugin-granwin')
方法说明
设备控制
方法名 |
入参 |
说明 |
getBlePermission |
plugin.getBlePermission(callback:Function) |
获取蓝牙是否授权,通过回调的形式返回信息 |
openBlueTooth |
plugin.openBlueTooth(callback:Function) |
通过原生控制方式,打开蓝牙,通过回调的形式返回信息 |
蓝牙配网
方法名 |
入参 |
说明 |
bleNotify |
plugin.bleNotify(callback:Function) |
将蓝牙搜索到的设备信息,通过回调返回 |
bleScan |
plugin.openBlueTooth(callback:Function) |
让设备开始扫描附近的蓝牙设备,搜索到的结果在 bleNotify 回调方法中将返回 |
connectBle |
plugin.connectBle(deviceName:string, callback:Function) |
蓝牙连接名称为 deviceName 的设备,回调中返回的结果 |
setEncryption |
plugin.setEncryption(code:number, callback:Function) |
设置蓝牙信息传输中的加密方式,1 v3加密(默认),回调中返回的结果 |
bleSetDeviceNetwork |
plugin.bleSetDeviceNetwork(SSID:string, password:string, URL:string, callback:Function) |
向设备通过蓝牙发送配网数据,回调中返回结果。SSID,配网的目标Wi-Fi名称;password,配网的目标Wi-Fi密码;URL,设备入网配置地址 |
Wi-Fi配网
方法名 |
入参 |
说明 |
connectWifi |
plugin.connectWifi(SSID:string, callback:Function) |
Wi-Fi连接名称为 SSID 的设备(设备配置中的Wi-Fi密码为默认值,不需要输入)回调中返回的结果 |
setEncryption |
plugin.setEncryption(code:number, callback:Function) |
设置UDP信息传输中的加密方式,1 v3加密(默认),回调中返回的结果 |
apSetDeviceNetwork |
plugin.apSetDeviceNetwork(SSID:string, password:string, URL:string, callback:Function) |
向设备通过UDP发送配网数据,回调中返回结果。SSID,配网的目标Wi-Fi名称;password,配网的目标Wi-Fi密码;URL,设备入网配置地址 |
蓝牙指令
方法名 |
入参 |
说明 |
bleControl |
plugin.bleControl(jsonStr:string, callback:Function) |
通过json字符串(JSON.stringify({99:{type:1,value:1}}) )的形式将设备的指令信息发送 |
setEncryption |
plugin.setEncryption(code:number, callback:Function) |
设置蓝牙指令信息传输中的加密方式,1 v3加密(默认),回调中返回的结果 |
bleQueryNotify |
plugin.bleQueryNotify(dpNames:string,callback:Function) |
监听dpNames中包含的dp点的值(1,2,3 )对应的属性点存在时,通过回调返回 |
aws相关
方法名 |
入参 |
说明 |
initAWS |
plugin.initAWS(clientId:string, mCustomerSpecificEndpoint:string, token:string, accountId:string, identityPoolId:string, mRegion:string, callback:Function}) |
初始化AWS的配置 |
setAWS |
plugin.setAWS(callback:Function) |
配置AWS的 |
示例
<template>
<view class="container">
<view class="simple-color">{{ message }}</view>
<view class="hr"></view>
<button @tap="bleAction" data-key="getBlePermission">获取蓝牙权限</button>
<button @tap="bleAction" data-key="openBlueTooth">打开蓝牙</button>
<view class="hr"></view>
<button @tap="bleAction" data-key="bleScan">蓝牙扫描</button>
<button @tap="bleAction" data-key="connectBle">蓝牙连接</button>
<button @tap="bleAction" data-key="setEncryption">设置加密方式</button>
<button @tap="bleAction" data-key="bleSetDeviceNetwork">传递蓝牙配网数据</button>
<button @tap="bleAction" data-key="bleNotify">蓝牙监听挂载</button>
<view class="hr"></view>
<button @tap="apAction" data-key="connectWifi">AP连接</button>
<button @tap="apAction" data-key="setEncryption">设置加密方式</button>
<button @tap="apAction" data-key="apSetDeviceNetwork">AP配网</button>
<view class="hr"></view>
<button @tap="bleAction" data-key="bleQueryNotify">蓝牙查询</button>
<button @tap="bleAction" data-key="setEncryption">设置加密方式</button>
<button @tap="bleAction" data-key="bleControl">蓝牙指令发送</button>
<view class="hr"></view>
<button @tap="awsAction" data-key="initAWS">初始化AWS</button>
<button @tap="awsAction" data-key="setAWS">设置AWS监听</button>
<view class="hr"></view>
<view style="height: 2upx;"></view>
</view>
</template>
<script>
const plugin = uni.requireNativePlugin('plugin-granwin')
const toast = (msg, _this = null) => {
if (_this) {
console.log(msg)
_this.message = msg
}
}
export default {
data() {
return {
message: '',
}
},
methods: {
awsAction({ currentTarget: { dataset: { key } } }) {
const _this = this
if (key === 'setAWS') {
plugin.setAWS(function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'initAWS') {
const clientId = 'us-west-2:eadc9aa0-98f9-465d-94fa-0946d6ebe535'
const mCustomerSpecificEndpoint = 'a3r68s0rrta0ju-ats.iot.us-west-2.amazonaws.com'
const token = 'eyJraWQiOiJ1cy13ZXN0LTIzIiwidHlwIjoiSldTIiwiYWxnIjoiUlM1MTIifQ.eyJzdWIiOiJ1cy13ZXN0LTI6ZWFkYzlhYTAtOThmOS00NjVkLTk0ZmEtMDk0NmQ2ZWJlNTM1IiwiYXVkIjoidXMtd2VzdC0yOjRiOGMxNDNkLTcyOWYtNDI4MC1hZjdhLWQzMWMyOGMwNDdiMiIsImFtciI6WyJhdXRoZW50aWNhdGVkIiwiZ3JhbndpbiIsImdyYW53aW46dXMtd2VzdC0yOjRiOGMxNDNkLTcyOWYtNDI4MC1hZjdhLWQzMWMyOGMwNDdiMjo3OTY2Mjk5MjAzOTM2MTMzMTJfc2FtLmZhbmdAZ3Jhbndpbi5jb21fODIxOTc5NDM3ODM2MjcxNjE2Il0sImlzcyI6Imh0dHBzOi8vY29nbml0by1pZGVudGl0eS5hbWF6b25hd3MuY29tIiwiaHR0cHM6Ly9jb2duaXRvLWlkZW50aXR5LmFtYXpvbmF3cy5jb20vaWRlbnRpdHktcG9vbC1hcm4iOiJhcm46YXdzOmNvZ25pdG8taWRlbnRpdHk6dXMtd2VzdC0yOjAwMTc5MTYxNDIyMzppZGVudGl0eXBvb2wvdXMtd2VzdC0yOjRiOGMxNDNkLTcyOWYtNDI4MC1hZjdhLWQzMWMyOGMwNDdiMiIsImV4cCI6MTY4Nzg0OTQxMywiaWF0IjoxNjg3NzYzMDEzfQ.eBgVdDrGEJovBglbwZvKEGmFlxE4qcuzG8aFsHdL1HtMXFqRFu1sz6BQiti4yi_-iQL8ANzpUrcubV9yeXdG43HoZbM9XBXWtv1MVQj9-4QGlS6HIsyhoh8KR6dqY3wG5eSqtu6OExu_-_ta5oqLEI_3vyb-qQz_RAYfOK3Gh7VV3ZYQEAK4nMCx9BCQ5P3g6C9vSLWFkcLSRQuE2KTA5oQKGpDyEHBkDCrQY5J2MFaqCpxBcdup5Ms8CuBoTlfGcep0IIhAT5VeUe8rGA_3XwiLFT6EoHKm5F6vKFvrfoEImETRZzcN_hnat2W01e-IBMSCzrNzZ6UFfriqejuWOQ'
const accountId = 'sam.fang@granwin.com'
const identityPoolId = 'us-west-2:4b8c143d-729f-4280-af7a-d31c28c047b2'
const mRegion = 'us-west-2'
plugin.initAWS(clientId, mCustomerSpecificEndpoint, token, accountId, identityPoolId, mRegion, function(res) {
toast(JSON.stringify(res), _this)
})
}
},
apAction({ currentTarget: { dataset: { key } } }) {
const _this = this
if (key === 'connectWifi') {
plugin.connectWifi('granwin-dev-1baf-BDD4', function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'apSetDeviceNetwork') {
plugin.apSetDeviceNetwork('Granwin', 'taobao888', 'https://oghafnxkic.execute-api.us-west-2.amazonaws.com/Prod', function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'setEncryption') {
plugin.setEncryption(1, function(res) {
toast(JSON.stringify(res), _this)
})
}
},
bleAction({ currentTarget: { dataset: { key } } }) {
const _this = this
if (key === 'getBlePermission') {
plugin.getBlePermission(function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'bleScan') {
plugin.bleScan(function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'connectBle') {
plugin.connectBle('granwin-dev', function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'setEncryption') {
plugin.setEncryption(1, function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'bleSetDeviceNetwork') {
plugin.bleSetDeviceNetwork('Granwin', 'taobao888', 'https://oghafnxkic.execute-api.us-west-2.amazonaws.com/Prod', function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'openBlueTooth') {
plugin.openBlueTooth(function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'bleControl') {
const jsonStr = JSON.stringify({"99":{"type":1,"value":1}})
plugin.bleControl(jsonStr, function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'bleNotify') {
plugin.bleNotify(function(res) {
toast(JSON.stringify(res), _this)
})
} else if (key === 'bleQueryNotify') {
plugin.bleQueryNotify('30,31,3,4,1,6,9,11,13,5,7,8,10,12', function(res) {
toast(JSON.stringify(res), _this)
})
}
},
}
}
</script>