my.getbledeviceservices(object object)
支付宝客户端 10.0.18 或更高版本; 若版本较低,建议采取 兼容处理 。
支小宝客户端 支持
安诊儿客户端 支持
小程序开发者工具: 不支持。请使用真机调试。
主体: 企业支付宝小程序 、 个人支付宝小程序
相关文档: 蓝牙 api 错误码对照表 、 蓝牙 api 概览 、 my.connectbledevice
获取指定低功耗蓝牙设备所有服务列表。
object object
查看示例
| 属性 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| deviceid | string | - | 是 | 蓝牙设备 id。该 deviceid 对应的蓝牙设备需要已经通过 my.connectbledevice 建立连接 |
| success | function | - | 否 | 调用成功的回调函数 |
| fail | function | - | 否 | 调用失败的回调函数 |
| complete | function | - | 否 | 调用结束的回调函数(调用成功、失败都会执行) |
success 回调函数
参数
object res
查看示例
| 属性 | 类型 | 描述 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| services | array | 已发现的设备服务列表 |
||||||||||
|
||||||||||||
fail 回调的参数为 object,error 属性为错误码,errormessage 属性为错误消息。
完整的错误码信息请查看蓝牙 api 错误码对照表。
| 错误码 | 错误消息 | 凯发app官方网站的解决方案 |
|---|---|---|
| 13 | 与系统服务的连接暂时丢失。 |
提示用户尝试重新连接。 |
my.getbledeviceservices js 代码
success 回调函数参数
page({
data:{
// 本数据为假数据。
deviceid: '37a514b8-1111-2222-abcd-d93b5e46fb50'
},
getbledeviceservices() {
my.getbledeviceservices({
deviceid: this.data.deviceid,
success: res => {
console.log(res.services)
},
fail: error => {
console.error('获取信息失败: ', json.stringify(error));
}
});
}
})
{
"services": [
{
"isprimary": true,
"serviceid": "00001800-0000-1000-8000-00805f9b34fb"
},
{
"isprimary": true,
"serviceid": "00001801-0000-1000-8000-00805f9b34fb"
},
{
"isprimary": true,
"serviceid": "d0611e78-bbb4-4591-a5f8-487910ae4366"
},
{
"isprimary": true,
"serviceid": "9fa480e0-4967-4542-9390-d343dc5d04ae"
}
]
}