p***@saipu.cc
p***@saipu.cc
  • 发布:2018-12-05 12:34
  • 更新:2018-12-06 15:16
  • 阅读:1900

为何IOS10可以调用蓝牙Ble,而IOS12不行呢?

分类:Native.js
2018-12-05 12:34 负责人:无 分享
已邀请:
p***@saipu.cc

p***@saipu.cc (作者)

var CBCentralManager = plus.ios.importClass("CBCentralManager");

var CBPeripheral=plus.ios.importClass("CBPeripheral");      
var NSDictionary=plus.ios.importClass("NSDictionary");      
var rssi=plus.ios.importClass("NSNumber");      
var outdevice=new CBPeripheral();  
console.log("outdevice:"+JSON.stringify(outdevice))  
var option=new NSDictionary();  
console.log("option:"+JSON.stringify(option))  

var manager = new CBCentralManager();  
var delegate = plus.ios.implements("CBCentralManagerDelegate",   
    {  
    "centralManagerDidUpdateState:":   
        function(central){  
            var state = manager.plusGetAttribute("state");  
            console.log("1、中央外设管理器状态" + JSON.stringify(manager));  
            console.log("1.1 蓝牙状态:"+state)  
            switch(state){  
                case 1:  
                    break;  
                case 2:  
                    break;  
                case 3:  

                    break;  
                case 4:  
                    plus.nativeUI.toast("蓝牙状态:关闭")  
                    break;  
                case 5:  
                    plus.nativeUI.toast("2、开始扫描蓝牙设备 ")  
                    console.log("2、开始扫描蓝牙设备 ")  
                    manager.stopScan();  
                    manager.scanForPeripheralsWithServicesoptions(null, null);  
                    break;  
                default:   
                    console.log("(default)蓝牙状态:"+state)  
            }  
        },  
    "centralManager:didDiscoverPeripheral:advertisementData:RSSI:":   
        function(central, peripheral, advertisementData, RSSI) {  
            plus.nativeUI.toast("3、发现Ble蓝牙.....  ")  
            console.log("发现Ble蓝牙..... ")  
            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");  
            console.log("name:"+name)   
            var uuid = peripheral.plusGetAttribute("identifier").plusGetAttribute("UUIDString");  
            var rssi = RSSI.plusGetAttribute("intValue");  
            console.log("uuid:"+uuid)  
            plus.nativeUI.toast("uuid:"+uuid)  
            console.log("rssi:"+rssi)  
        }  
});  

manager.initWithDelegatequeueoptions(delegate,null);  

上述代码在IOS10.3.3苹果手机可以进入didDiscoverPeripheral,但在IOS12.1苹果手机闪退,请教各位是哪里没有蓝牙权限吗?

该问题目前已经被锁定, 无法添加新回复