Bana
Bana
  • 发布:2017-04-24 09:36
  • 更新:2018-12-16 07:01
  • 阅读:2131

native 调用苹果蓝牙

分类:Native.js

<!DOCTYPE html>  
<html>  

    <head>  
        <meta charset="UTF-8">  
        <title></title>  
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
        <title></title>  
        <script src="js/mui.min.js"></script>  
        <script src="js/sbbluetooth.js"></script>  
        <link href="css/mui.min.css" rel="stylesheet" />  
    </head>  

    <body>  
        <header class="mui-bar mui-bar-nav">  
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>  
            <h1 class="mui-title">附近蓝牙</h1>  
        </header>  
        <div class="mui-content">  
        </div>  
    </body>  
    <script type="text/javascript">  
        mui.init()  
        var CBCentralManager = plus.ios.import("CBCentralManager");  
        var manager = new CBCentralManager();  
        mui.plusReady(function() {  
            searchIOS()  
        })  

        function searchIOS() {  
            var delegate = plus.ios.implements("CBCentralManagerDelegate", {  
                "centralManagerDidUpdateState:": centralManagerDidUpdateState,  
                  "centralManager:didDiscoverPeripheral:advertisementData:RSSI:": didDiscoverPeripheral  
            });  
            var delegate2 = plus.ios.implements("CBPeripheralDelegate",{  
            })  
            manager.initWithDelegatequeue(delegate, null);  
        }  

        function centralManagerDidUpdateState(central) {  
            //console.log(central);  
            var state = central.plusGetAttribute('state');  
            console.log(state);  
            if(state == 4) {  
                console.log('请开启蓝牙');  
            }  
            if(state == 5) {  
                console.log("中央外设管理器状态 state= " + state);  
                manager.scanForPeripheralsWithServicesoptions(null, null);  
            }  
        }  
        function didDiscoverPeripheral(central, peripheral, advertisementData, RSSI) {  
            console.log(JSON.stringify(central))  
            var name = peripheral.plusGetAttribute("name");  
            var uuid = peripheral.plusGetAttribute("identifier").plusGetAttribute("UUIDString");  
            var rssi = RSSI.plusGetAttribute("intValue");  
            console.log("蓝牙设备:"+ name + " " + uuid + " " + rssi + " " + dist + "米");  

        }   

        function calcDistByRSSI(rssi, a, n) {  
            var rs = Math.abs(rssi);  
            var power = (rs - a) / (10 * n);  
            return Math.pow(10, parseFloat(power)).toFixed(2);  
        }  
    </script>  

</html>

didDiscoverPeripheral 这个方法始终不走,请问有大神知道吗

2017-04-24 09:36 1 条评论 负责人:无 分享
已邀请:
4***@qq.com

4***@qq.com

求解

DCloud_heavensoft

DCloud_heavensoft

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