更新记录
1.0.3(2025-05-19) 下载此版本
1.0.3
1.0.2(2025-03-24) 下载此版本
1.0.2
1.0.1(2025-02-19) 下载此版本
1.0.1
查看更多平台兼容性
uni-app x
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | × | × | √ | - |
鸿蒙中单独调用
import { createBLEConnection } from '@/uni_modules/srh-BluetoothAdapter';
createBLEConnection({
deviceId: 'xxx',
success: (res) => {
},
fail:(e) => {
}
})
兼容uniapp写法, 新建文件index.ts
import { createBLEConnection } from '@/uni_modules/srh-BluetoothAdapter';
interface UniExtensions {
createBLEConnection : typeof createBLEConnection;
}
const $uni : UniExtensions = {
createBLEConnection
};
export default $uni;
另建一个main.ts文件
// #ifdef APP-HARMONY
import $uni from './index.ts';
// #endif
// #ifdef APP-PLUS
const $uni = uni;
// #endif
export { $uni }
页面中导入main.ts
import {$uni} from '@/main.ts';
$uni.createBLEConnection({
deviceId: 'xxx',
success: (res) => {
},
fail:(e) => {
}
})
支持的API
openBluetoothAdapter,
closeBLEConnection,
closeBluetoothAdapter,
onBluetoothDeviceFound,
createBLEConnection,
getBLEDeviceCharacteristics,
getBLEDeviceServices,
getBluetoothDevices,
notifyBLECharacteristicValueChange,
onBLECharacteristicValueChange,
onBLEConnectionStateChange,
setBLEMTU,
startBluetoothDevicesDiscovery,
stopBluetoothDevicesDiscovery,
writeBLECharacteristicValue,
getBLEDeviceRSSI
注意: 插件过滤了uuid,如果需要请在config.uts自行添加