4982关注15449浏览
手机(ios 安卓)蓝牙搜索始终搜索不到设备, 只能搜索到电脑蓝牙。
ios连接电脑蓝牙失败,安卓连接电脑蓝牙失败。
//index.js
//获取应用实例
var app = getApp();
Page({
data: {
status: "",
sousuo: "",
connectedDeviceId: "", //已连接设备uuid
services: "", // 连接设备的服务
characteristics: "", // 连接设备的状态值
writeServicweId: "", // 可写服务uuid
writeCharacteristicsId: "",//可写特征值uuid
readServicweId: "", // 可读服务uuid
readCharacteristicsId: "",//可读特征值uuid
notifyServicweId: "", //通知服务UUid
notifyCharacteristicsId: "", //通知特征值UUID
inputValue: "",
characteristics1: "", // 连接设备的状态值
},
onLoad: function () {
if (wx.openBluetoothAdapter) {
wx.openBluetoothAdapter()
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},
// 初始化蓝牙适配器
lanya1: function () {
var that = this;
wx.openBluetoothAdapter({
success: function (res) {
that.setData({
msg: "初始化蓝牙适配器成功!" + JSON.stringify(res),
})
//监听蓝牙适配器状态
wx.onBluetoothAdapterStateChange(function (res) {
that.setData({
sousuo: res.discovering ? "在搜索。" : "未搜索。",
status: res.available ? "可用。" : "不可用。",
})
})
}
})
},
// 本机蓝牙适配器状态
lanya2: function () {
var that = this;
wx.getBluetoothAdapterState({
success: function (res) {
that.setData({
msg: "本机蓝牙适配器状态" + "/" + JSON.stringify(res.errMsg),
sousuo: res.discovering ? "在搜索。" : "未搜索。",
status: res.available ? "可用。" : "不可用。",
})
//监听蓝牙适配器状态
wx.onBluetoothAdapterStateChange(function (res) {
that.setData({
sousuo: res.discovering ? "在搜索。" : "未搜索。",
status: res.available ? "可用。" : "不可用。",
})
})
}
})
},
//搜索设备
lanya3: function () {
var that = this;
wx.startBluetoothDevicesDiscovery({
success: function (res) {
that.setData({
msg: "搜索设备" + JSON.stringify(res),
})
-
至过去的我
2044人对此回答表示赞同
我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>