使用chrome连接iOS设备.bluetoothLowEnergy API



我一直在尝试使用BLE使用Chrome连接iPhone 5到OSX Chrome(版本38.0.2096.0 dev)。bluetoothLowEnergy API。

我在我的iphone上使用BLE实用程序来模拟电池服务。我可以使用其他手机或OSX工具发现该服务并连接到它,但我在使用chrome时遇到了问题。我可以看到我的设备列表,但没有发现服务,当我尝试连接到设备时,连接失败,显示以下消息:

操作失败

我将非常感谢你的帮助。

下面是我的代码:

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);

据我所知,Mac上的BLE实现尚未完成。跟踪API开发的一个好地方是Chrome问题跟踪器。这是一个与Mac相关问题的链接。要查看所有蓝牙更改,只需在open issues下搜索蓝牙

相关内容

  • 没有找到相关文章

最新更新