我使用的是demo代码,但是总是报错  ,这是没什么呢?(小白一枚,求指导)
09:08:40.734  Uncaught TypeError: Cannot read property 'openBluetoothAdapter' of undefined at index.html:14
09:08:44.703  Uncaught TypeError: Cannot read property 'getBluetoothAdapterState' of undefined at index.html:25
09:08:45.516  Uncaught TypeError: Cannot read property 'closeBluetoothAdapter' of undefined at index.html:36
09:08:46.828  Uncaught TypeError: Cannot read property 'openBluetoothAdapter' of undefined at index.html:14
代码如下:
<!DOCTYPE html>  
<html>  
    <head>  
    <meta charset="utf-8">  
    <title>Bluetooth Example</title>  
    <script type="text/javascript" >  
// 扩展API加载完毕后调用onPlusReady回调函数   
document.addEventListener('plusready', onPlusReady, false);  
// 扩展API加载完毕,现在可以正常调用扩展API  
function onPlusReady(){  
}  
// 打开蓝牙模块  
function openBluetoothAdapter(){  
    plus.Bluetooth.openBluetoothAdapter({  
        success:function(e){  
            console.log('open success: '+JSON.stringify(e));  
        },  
        fail:function(e){  
            console.log('open failed: '+JSON.stringify(e));  
        }  
    });  
}  
// 获取蓝牙状态  
function getBluetoothState(){  
    plus.Bluetooth.getBluetoothAdapterState({  
        success:function(e){  
            console.log('state success: '+JSON.stringify(e));  
        },  
        fail:function(e){  
            console.log('state failed: '+JSON.stringify(e));  
        }  
    });  
}  
// 关闭蓝牙模块  
function closeBluetoothAdapter(){  
    plus.Bluetooth.closeBluetoothAdapter({  
        success:function(e){                                              
            console.log('close success: '+JSON.stringify(e));  
        },  
        fail:function(e){  
            console.log('close failed: '+JSON.stringify(e));  
        }  
    });  
}  
    </script>  
    </head>  
    <body >  
        <button onclick="openBluetoothAdapter()">打开蓝牙模块</button>  
        <br/>  
        <button onclick="getBluetoothState()">获取蓝牙状态</button>  
        <br/>  
        <button onclick="closeBluetoothAdapter()">关闭蓝牙模块</button>  
    </body>  
</html> 
             
             
             
			 
                                        
                                     
                                                                     
                                                                     
                                                                     
                                                                     
            
z***@gmail.com
是不是你用的不是HBuilderX?要新版才有这个api
2019-03-28 06:38
z***@gmail.com
用X就好了。
2019-04-19 03:11