native.js IOS蓝牙发现不了外设,用OC编写的原生的就是可以的

native.js IOS蓝牙发现不了外设,用OC编写的原生的就是可以的



2018-01-26 15:38 添加评论 分享
已邀请:

最佳回复

0

DCloud_heavensoft

赞同来自:

更新:5+已提供蓝牙,参考http://www.html5plus.org/doc/zh_cn/bluetooth.html 注意需要最新版HBuilderX 1.3


1

嘿嘿,花3000块钱去申请付费问答吧


0

164406769@qq.com

赞同来自:

export default {
name: "Bluetooth-test",
created() {

},
mounted() {

},
destroyed() {
//删除对象
if (this.central) {
plus.ios.deleteObject(this.central);
}
},
data() {
return {
// central:null
}
},
methods: {
testBluetooth() {
//调用IOS的蓝牙相关库
let CBCentralManager = plus.ios.importClass("CBCentralManager");
let centralObject = new CBCentralManager();
let delegate = plus.ios.implements("CBCentralManagerDelegate", {
"centralManagerDidUpdateState:": this.centerManagerDidUpdateState,
"centralManager:didDiscoverPeripheral:advertisementData:RSSI:": this.didDiscoverPeripheral
});
//初始化CentralManager对象
centralObject.initWithDelegatequeue(delegate, null);
},
centerManagerDidUpdateState(central) {
let state = central.plusGetAttribute("state");
console.log("中央外设管理器状态" + JSON.stringify(central));
console.log("state=" + state);
switch (state) {
case 0:
console.log("蓝牙状态未知");
break;
//CBCentralManagerStateResetting
case 1:
console.log("蓝牙已重置");
break;
//CBCentralManagerStateUnsupported
case 2:
console.log("不支持蓝牙");
break;
//CBCentralManagerStateUnauthorized
case 3:
console.log("蓝牙未认证");
break;
//CBCentralManagerStatePoweredOff
case 4:
console.log("蓝牙未开启");
break;
//CBCentralManagerStatePoweredOn
case 5:
{
console.log("蓝牙已开启");
let NSDictionary = plus.ios.importClass("NSDictionary");
let option = new NSDictionary();
let result = central.scanForPeripheralsWithServicesoptions(null, option);
console.log(result);
console.log(central.scanForPeripheralsWithServicesoptions);
}
break;
}
},
didDiscoverPeripheral(central, peripheral, advertisementData, RSSI) {
console.log("他妈的终于进来了");
console.log(arguments);
// console.log("central:" + JSON.stringify(central))
// console.log("peripheral:" + JSON.stringify(peripheral))
// console.log("advertisementData:" + JSON.stringify(advertisementData))
// console.log("RSSI:" + JSON.stringify(RSSI))
// var name = peripheral.plusGetAttribute("name");
// var uuid = peripheral.plusGetAttribute("identifier").plusGetAttribute("UUIDString");
// var rssi = RSSI.plusGetAttribute("intValue");
}
}
}


0

164406769@qq.com

赞同来自:

上面是代码,发现外设的回调怎么都进不去,Xcode开发的原生代码就是可以 的


0

164406769@qq.com

赞同来自:

又无人回答吗~~~


0

164406769@qq.com

赞同来自:

有大神或者官方工作人员解答下吗~


0

164406769@qq.com

赞同来自:

因为大家经常问我解决没,所以这边说下结果,问题最终未得到解决,放弃了此调用方式,走原生了


要回复问题请先登录注册