aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/bluetooth
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/bluetooth
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/bluetooth')
-rw-r--r--files/zh-cn/web/api/bluetooth/index.html114
-rw-r--r--files/zh-cn/web/api/bluetooth/requestdevice/index.html145
2 files changed, 259 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/bluetooth/index.html b/files/zh-cn/web/api/bluetooth/index.html
new file mode 100644
index 0000000000..cd46b72ee7
--- /dev/null
+++ b/files/zh-cn/web/api/bluetooth/index.html
@@ -0,0 +1,114 @@
+---
+title: Bluetooth
+slug: Web/API/Bluetooth
+tags:
+ - API
+ - 接口
+ - 网页蓝牙接口说明
+ - 蓝牙
+ - 说明
+translation_of: Web/API/Bluetooth
+---
+<p>{{ apiref("Web Bluetooth API") }} {{Non-standard_header()}}</p>
+
+<p><a href="/Web/API/Web_Bluetooth_API">Web Bluetooth API</a> 的<strong><code>Bluetooth</code></strong><code>接口</code>返回指代{{domxref("BluetoothDevice")}}带有指定选项的对象的{{jsxref("Promise")}}。</p>
+
+<h2 id="接口">接口</h2>
+
+<pre class="syntaxbox">interface <dfn>Bluetooth</dfn> {
+ Promise&lt;BluetoothDevice&gt; requestDevice(RequestDeviceOptions <dfn>options</dfn>);
+};
+Bluetooth implements EventTarget;
+Bluetooth implements BluetoothDeviceEventHandlers;
+Bluetooth implements CharacteristicEventHandlers;
+Bluetooth implements ServiceEventHandlers;</pre>
+
+<h2 id="特性">特性</h2>
+
+<dl>
+ <dt>无</dt>
+</dl>
+
+<h2 id="方法">方法</h2>
+
+<dl>
+ <dt>{{domxref("Bluetooth.requestDevice()")}}</dt>
+ <dd>返回一个包含指定选项的{{domxref("BluetoothDevice")}}对象的{{jsxref("Promise")}}。</dd>
+</dl>
+
+<h2 id="详细说明">详细说明</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Web Bluetooth', '#bluetooth', 'Bluetooth')}}</td>
+ <td>{{Spec2('Web Bluetooth')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome (45.0)}} [1]</td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ <td>{{CompatChrome (48.0)}} [2]</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] 注意事项:仅谷歌浏览器可用</p>
+
+<p>[2] 注意事项:仅安卓6以上可用</p>
diff --git a/files/zh-cn/web/api/bluetooth/requestdevice/index.html b/files/zh-cn/web/api/bluetooth/requestdevice/index.html
new file mode 100644
index 0000000000..abfad37108
--- /dev/null
+++ b/files/zh-cn/web/api/bluetooth/requestdevice/index.html
@@ -0,0 +1,145 @@
+---
+title: Bluetooth.requestDevice()
+slug: Web/API/Bluetooth/requestDevice
+tags:
+ - API
+ - Web蓝牙
+ - 蓝牙
+translation_of: Web/API/Bluetooth/requestDevice
+---
+<p>{{APIRef()}}{{SeeCompatTable}}</p>
+
+<p>{{domxref("Bluetooth")}}接口的<strong><code>Bluetooth.requestDevice()</code></strong>方法返回一个带有对应options的{{domxref("BluetoothDevice")}}对象的{{jsxref("Promise")}}对象. 如果没有蓝牙设备选择界面,则此方法返回与条件匹配的第一个设备。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">Bluetooth.requestDevice(options).then(function(bluetoothDevice) { ... })</pre>
+
+<h3 id="返回值">返回值</h3>
+
+<p>带有{{domxref("BluetoothDevice")}} 对象的{{jsxref("Promise")}} 对象.</p>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>options </dt>
+ <dd>设置设备请求选项的对象. 可用的选项是:
+ <ul>
+ <li><code>filters[]</code>: 一个BluetoothScanFilters数组。 此过滤器由一个BluetoothServiceUUID数组,一个名称参数和一个namePrefix参数组成。</li>
+ <li><code>optionalServices[]</code>: 一个BluetoothServiceUUID数组。</li>
+ <li><code>acceptAllDevices</code>: boolean 表示请求脚本可以接受所有蓝牙设备。 默认值为false。</li>
+ </ul>
+ </dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<pre><code>//扫描选项匹配任何设备广播:
+
+//. 标准心率服务。
+
+//. 两个16位服务ID 0x1802和0x1803。
+
+//. 专有的128位UUID服务c48e6067-5295-48d3-8d5c-0395f61792b1。
+
+//. 名称为“设备名”的设备。
+
+//. 名称以“前缀”开头的设备。
+
+//
+
+//如果设备包含电池服务,
+
+//即使设备不通告该服务,也可以访问电池服务。
+
+let options = {
+ filters: [
+ {services: ['heart_rate']},
+ {services: [0x1802, 0x1803]},
+ {services: ['c48e6067-5295-48d3-8d5c-0395f61792b1']},
+ {name: '设备名'},
+ {namePrefix: '前缀'}
+ ],
+ optionalServices: ['battery_service']
+}
+
+navigator.bluetooth.requestDevice(options).then(function(device) {
+ console.log('名称: ' + device.name);
+ // 在此处实现设备调用
+})
+.catch(function(error) {
+ console.log("出现错误: " + error);
+});</code></pre>
+
+<p>查看<a href="https://webbluetoothcg.github.io/web-bluetooth/#example-filter-by-services">详细示例</a> </p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">说明</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Web Bluetooth', '#dom-bluetooth-requestdevice', 'requestDevice()')}}</td>
+ <td>{{Spec2('Web Bluetooth')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome (56)}}</td>
+ <td> </td>
+ <td> </td>
+ <td>{{CompatOpera(43)}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android Webview</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome (56)}}</td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ <td>{{CompatOperaMobile(43)}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+</div>