本文介绍了连接到使用chrome.bluetoothLowEnergy API iOS设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试一个iPhone 5使用了API chrome.bluetoothLowEnergy BLE连接到OSX浏览器(版本38.0.2096.0 DEV)。
我使用的我iphone模拟电池服务。我能发现该服务并使用其他手机或 OSX效用连接到它一>,但我有镀铬这样的问题。我可以看到我列出的设备,但没有发现服务,当我尝试连接到该设备,连接失败,出现以下消息:
I would greatly appreciate any help.
Here is my code:
manifest.json
{
"name": "BLE Test",
"description": "Chrome BLE Test",
"version": "1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"bluetooth": {
"low_energy": true,
"uuids": ["180f"]
}
}
index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Chrome BLE Test</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
</body>
</html>
script.js
function main() {
var onGetServicesCallback = function(services) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
console.log('Services:', services.length);
if (!services) {
console.log('No services');
return;
}
services.forEach(function(service) {
console.log(service);
});
}
chrome.bluetooth.getDevices(function(devices) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
console.log('Found devices:', devices.length);
if (devices) {
devices.forEach(function(device) {
console.log('Device name:', device.name);
chrome.bluetoothLowEnergy.getServices(device.address, onGetServicesCallback);
chrome.bluetoothLowEnergy.connect(device.address, function() {
if (chrome.runtime.lastError) {
console.log('Connection failed:', chrome.runtime.lastError.message);
return;
}
console.log('Connected!');
});
});
}
});
}
document.addEventListener('DOMContentLoaded', main);
解决方案
The BLE implementation for the Mac is not complete yet as far as I know. A good place to follow the development of the API is on the Chrome issue tracker. This is a link to the issue related to the Mac one specifically. To see all the bluetooth changes, just search for bluetooth under open issues.
这篇关于连接到使用chrome.bluetoothLowEnergy API iOS设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!