微信小程序蓝牙功能开发

本文介绍了微信小程序从1.1.0版本开始支持的蓝牙功能,包括iOS客户端6.5.6以上的支持情况和Android的不支持状态。蓝牙功能涉及18个API接口,分为搜索、连接和通信三大类。详细使用方法可参照官方文档,同时提供了搜索蓝牙设备和连接获取数据的案例实现,并展示了最终效果。
摘要由CSDN通过智能技术生成

微信小程序蓝牙功能开发:

1.简述

蓝牙适配器接口是基础库版本 1.1.0 开始支持。 
iOS 微信客户端 6.5.6 版本开始支持,Android 客户端暂不支持 
蓝牙总共增加了18个api接口。

2.Api分类

搜索类 
连接类 
通信类

3.API的具体使用

详细见官网:

https://mp.weixin.qq.com/debug/wxadoc/dev/api/bluetooth.html#wxgetconnectedbluethoothdevicesobject

4. 案例实现

4.1 搜索蓝牙设备

/**
 * 搜索设备界面
 */
Page({
  data: {
    logs: [],
    list:[],
  },
   onLoad: function () {
    console.log('onLoad')
var that = this;
// const SDKVersion = wx.getSystemInfoSync().SDKVersion || '1.0.0'
// const [MAJOR, MINOR, PATCH] = SDKVersion.split('.').map(Number)
// console.log(SDKVersion);
// console.log(MAJOR);
// console.log(MINOR);
// console.log(PATCH);

// const canIUse = apiName => {
    
//   if (apiName === 'showModal.cancel') {
    
//     return MAJOR >= 1 && MINOR >= 1
//   }
//   return true
// }

// wx.showModal({
    
//   success: function(res) {
    
//     if (canIUse('showModal.cancel')) {
    
//       console.log(res.cancel)
//     }
//   }
// })
     //获取适配器
      wx.openBluetoothAdapter({
      success: function(res){
        // success
        console.log("-----success----------");
         console.log(res);
         //开始搜索
       wx.startBluetoothDevicesDiscovery({
  services: [],
  success: function(res){
    // success
     console.log("-----startBluetoothDevicesDiscovery--success----------");
     console.log(res);
  },
  fail: function(res) {
    // fail
     console.log(res);
  },
  complete: function(res) {
    // complete
     console.log(res);
  }
})


      },
      fail: function(res) {
         console.log("-----fail----------");
        // fail
         console.log(res);
      },
      complete: function(res) {
        // complete
         console.log("-----complete----------");
         console.log(res);
      }
    })

     wx.getBluetoothDevices({
       success: function(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值