admin 发表于 2023-2-16 18:54:49

Proximity模块管理设备距离传感器,可获取当前设备的接近距离信息,通过plus.proximit ...

<div id="article_content" class="article_content clearfix">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
                <div id="content_views" class="htmledit_views">
                  <h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">方法&#xff1a;</span></strong></span></h2>
<ul><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837161#plus.proximity.getCurrentProximity">getCurrentProximity</a>: 获取当前设备的接近距离信息</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837161#plus.proximity.watchProximity">watchProximity</a>: 监听设备接近距离的变化</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837161#plus.proximity.clearWatch">clearWatch</a>: 关闭监听设备接近距离变化</li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">回调方法&#xff1a;</span></strong></span></h2>
<ul><li><ahref="https://www.html5plus.org/doc/zh_cn/proximity.html#plus.proximity.ProximitySuccessCallback">ProximitySuccessCallback</a>: 获取设备接近距离信息成功的回调函数</li><li><ahref="https://www.html5plus.org/doc/zh_cn/proximity.html#plus.proximity.ProximityErrorCallback">ProximityErrorCallback</a>: 获取设备接近距离信息失败的回调函数</li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">权限&#xff1a;</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">5&#43;功能模块&#xff08;permissions&#xff09;</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
<span style&#61;&#34;color:#ffffff&#34;>{</span>
<span style&#61;&#34;color:#87ceeb&#34;>// ...</span>
<span style&#61;&#34;color:#ffa0a0&#34;>&#34;permissions&#34;</span><span style&#61;&#34;color:#ffffff&#34;>:{</span>
        <span style&#61;&#34;color:#87ceeb&#34;>// ...</span>
        <span style&#61;&#34;color:#ffa0a0&#34;>&#34;Proximity&#34;</span><span style&#61;&#34;color:#ffffff&#34;>:</span> <span style&#61;&#34;color:#ffffff&#34;>{</span>
                <span style&#61;&#34;color:#ffa0a0&#34;>&#34;description&#34;</span><span style&#61;&#34;color:#ffffff&#34;>:</span> <span style&#61;&#34;color:#ffa0a0&#34;>&#34;距离感应器&#34;</span>
        <span style&#61;&#34;color:#ffffff&#34;>}</span>
<span style&#61;&#34;color:#ffffff&#34;>}</span>
<span style&#61;&#34;color:#ffffff&#34;>}</span>
                        </code></span></span></code></pre>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_5-->getCurrentProximity</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">获取当前设备的接近距离信息</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
<span style&#61;&#34;color:#f0e68c&#34;><strong>void</strong></span><span style&#61;&#34;color:#ffffff&#34;> plus</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>proximity</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>getCurrentProximity</span><span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> successCB</span><span style&#61;&#34;color:#ffffff&#34;>,</span><span style&#61;&#34;color:#ffffff&#34;> errorCB </span><span style&#61;&#34;color:#ffffff&#34;>);</span>
                                </code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明&#xff1a;</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">获取当前接近设备的距离信息&#xff0c;距离值单位为厘米。如果感应器无法获取准确的距离值&#xff0c;则在接近设备时返回0&#xff0c;否则返回Infinity。 获取成功则调用successCB回调函数返接近回距离值。获取失败则调用errorCB回调函数错误信息。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数&#xff1a;</span></strong></span></h2>
<ul><li>successCB: <em>( <ahref="https://www.html5plus.org/doc/zh_cn/proximity.html#plus.proximity.ProximitySuccessCallback">ProximitySuccessCallback</a> ) 必选 </em>获取距离信息成功回调函数 <p style="margin-left:0;"></p> </li><li>errorCB: <em>( <ahref="https://www.html5plus.org/doc/zh_cn/proximity.html#plus.proximity.ProximityErrorCallback">ProximityErrorCallback</a> ) 可选 </em>获取距离信息失败回调函数 <p style="margin-left:0;"></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值&#xff1a;</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">平台支持&#xff1a;</span></strong></span></h2>
<ul><li>Android - 2.2&#43; (支持) : <p style="margin-left:0;"><span style="color:#474747;">支持</span></p> </li><li>iOS - 4.3&#43; (支持) : <p style="margin-left:0;"><span style="color:#474747;">支持</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">示例&#xff1a;</span></strong></span></h2>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
                               
<span style&#61;&#34;color:#cccccc&#34;><!DOCTYPE html></span>
<span style&#61;&#34;color:#f0e68c&#34;><strong><html></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><head></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><meta</strong></span> <span style&#61;&#34;color:#bdb76b&#34;><strong>charset</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>&#34;utf-8&#34;</span><span style&#61;&#34;color:#f0e68c&#34;><strong>></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><title></strong></span><span style&#61;&#34;color:#ffffff&#34;>Proximity Example</span><span style&#61;&#34;color:#f0e68c&#34;><strong></title></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><script</strong></span> <span style&#61;&#34;color:#bdb76b&#34;><strong>type</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>&#34;text/javascript&#34;</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>></strong></span>
<span style&#61;&#34;color:#87ceeb&#34;>// 扩展API加载完毕后调用onPlusReady回调函数 </span><span style&#61;&#34;color:#ffffff&#34;>
document</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>addEventListener</span><span style&#61;&#34;color:#ffffff&#34;>(</span> <span style&#61;&#34;color:#ffa0a0&#34;>&#34;plusready&#34;</span><span style&#61;&#34;color:#ffffff&#34;>,</span><span style&#61;&#34;color:#ffffff&#34;> onPlusReady</span><span style&#61;&#34;color:#ffffff&#34;>,</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>false</strong></span> <span style&#61;&#34;color:#ffffff&#34;>);</span>
<span style&#61;&#34;color:#87ceeb&#34;>// 扩展API加载完毕&#xff0c;现在可以正常调用扩展API</span>
<span style&#61;&#34;color:#f0e68c&#34;><strong>function</strong></span><span style&#61;&#34;color:#ffffff&#34;> onPlusReady</span><span style&#61;&#34;color:#ffffff&#34;>()</span> <span style&#61;&#34;color:#ffffff&#34;>{</span>
<span style&#61;&#34;color:#ffffff&#34;>}</span>
<span style&#61;&#34;color:#f0e68c&#34;><strong>function</strong></span><span style&#61;&#34;color:#ffffff&#34;> getProximity</span><span style&#61;&#34;color:#ffffff&#34;>()</span> <span style&#61;&#34;color:#ffffff&#34;>{</span><span style&#61;&#34;color:#ffffff&#34;>
        plus</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>proximity</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>getCurrentProximity</span><span style&#61;&#34;color:#ffffff&#34;>(</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>function</strong></span> <span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> d </span><span style&#61;&#34;color:#ffffff&#34;>)</span> <span style&#61;&#34;color:#ffffff&#34;>{</span><span style&#61;&#34;color:#ffffff&#34;>
                        alert</span><span style&#61;&#34;color:#ffffff&#34;>(</span> <span style&#61;&#34;color:#ffa0a0&#34;>&#34;Get distance success: &#34;</span><span style&#61;&#34;color:#ffffff&#34;>&#43;</span><span style&#61;&#34;color:#ffffff&#34;>d </span><span style&#61;&#34;color:#ffffff&#34;>);</span>
                <span style&#61;&#34;color:#ffffff&#34;>},</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>function</strong></span> <span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> e </span><span style&#61;&#34;color:#ffffff&#34;>)</span> <span style&#61;&#34;color:#ffffff&#34;>{</span><span style&#61;&#34;color:#ffffff&#34;>
                        alert</span><span style&#61;&#34;color:#ffffff&#34;>(</span> <span style&#61;&#34;color:#ffa0a0&#34;>&#34;Error: &#34;</span><span style&#61;&#34;color:#ffffff&#34;>&#43;</span><span style&#61;&#34;color:#ffffff&#34;>e</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>message </span><span style&#61;&#34;color:#ffffff&#34;>);</span>
                <span style&#61;&#34;color:#ffffff&#34;>}</span> <span style&#61;&#34;color:#ffffff&#34;>);</span>
<span style&#61;&#34;color:#ffffff&#34;>}</span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong></script></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong></head></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><body</strong></span> <span style&#61;&#34;color:#f0e68c&#34;><strong>></strong></span>
                <span style&#61;&#34;color:#f0e68c&#34;><strong><input</strong></span> <span style&#61;&#34;color:#bdb76b&#34;><strong>type</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>'button'</span> <span style&#61;&#34;color:#bdb76b&#34;><strong>onclick</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>'</span><span style&#61;&#34;color:#ffffff&#34;>getProximity</span><span style&#61;&#34;color:#ffffff&#34;>();</span><span style&#61;&#34;color:#ffa0a0&#34;>'</span> <span style&#61;&#34;color:#bdb76b&#34;><strong>value</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>'Proximity'</span><span style&#61;&#34;color:#f0e68c&#34;><strong>/></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong></body></strong></span>
<span style&#61;&#34;color:#f0e68c&#34;><strong></html></strong></span>
                               
                                </code></span></span></code></pre>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><ahref="https://uniapp.dcloud.io/use-html5plus">uni-app使用plus注意事项</a></span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_9-->watchProximity</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">监听设备接近距离的变化</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
<span style&#61;&#34;color:#98fb98&#34;>Number</span><span style&#61;&#34;color:#ffffff&#34;> plus</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>proximity</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>watchProximity</span><span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> changeCB</span><span style&#61;&#34;color:#ffffff&#34;>,</span><span style&#61;&#34;color:#ffffff&#34;> errorCB </span><span style&#61;&#34;color:#ffffff&#34;>);</span>
                                </code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明&#xff1a;</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">watchProximity将监听设备的接近距离信息变化事件&#xff0c;当接近距离发生变化时通过changeCB回调函数返回距离值。监听距离变化事件失败则通过errorCB回调函数返回错误信息。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数&#xff1a;</span></strong></span></h2>
<ul><li>changeCB: <em>( <ahref="https://blog.csdn.net/qq_40575646/article/details/122837161#plus.proximity.ProximitySuccessCallback">ProximitySuccessCallback</a> ) 必选 </em>设备接近距离变化时的回调函数 <p style="margin-left:0;"></p> </li><li>errorCB: <em>( <ahref="https://blog.csdn.net/qq_40575646/article/details/122837161#plus.proximity.ProximityErrorCallback">ProximityErrorCallback</a> ) 可选</em> <p style="margin-left:0;"><span style="color:#474747;">监听设备接近距离变化事件失败的回调函数</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值&#xff1a;</span></strong></span></h2>
<p>Number<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 用于标识接近距离变化事件监听器&#xff0c;可通过clearWatch方法取消监听。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">平台支持&#xff1a;</span></strong></span></h2>
<ul><li>Android - 2.2&#43; (支持) : <p style="margin-left:0;"><span style="color:#474747;">支持</span></p> </li><li>iOS - 4.3&#43; (支持) : <p style="margin-left:0;"><span style="color:#474747;">支持</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">示例&#xff1a;</span></strong></span></h2>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
<span style&#61;&#34;color:#cccccc&#34;><!DOCTYPE html></span>
<span style&#61;&#34;color:#f0e68c&#34;><strong><html></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><head></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><meta</strong></span> <span style&#61;&#34;color:#bdb76b&#34;><strong>charset</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>&#34;utf-8&#34;</span><span style&#61;&#34;color:#f0e68c&#34;><strong>></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><title></strong></span><span style&#61;&#34;color:#ffffff&#34;>Proximity Example</span><span style&#61;&#34;color:#f0e68c&#34;><strong></title></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><script</strong></span> <span style&#61;&#34;color:#bdb76b&#34;><strong>type</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>&#34;text/javascript&#34;</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>></strong></span>
<span style&#61;&#34;color:#87ceeb&#34;>// 扩展API加载完毕后调用onPlusReady回调函数 </span><span style&#61;&#34;color:#ffffff&#34;>
document</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>addEventListener</span><span style&#61;&#34;color:#ffffff&#34;>(</span> <span style&#61;&#34;color:#ffa0a0&#34;>&#34;plusready&#34;</span><span style&#61;&#34;color:#ffffff&#34;>,</span><span style&#61;&#34;color:#ffffff&#34;> onPlusReady</span><span style&#61;&#34;color:#ffffff&#34;>,</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>false</strong></span> <span style&#61;&#34;color:#ffffff&#34;>);</span>
<span style&#61;&#34;color:#87ceeb&#34;>// 扩展API加载完毕&#xff0c;现在可以正常调用扩展API</span>
<span style&#61;&#34;color:#f0e68c&#34;><strong>function</strong></span><span style&#61;&#34;color:#ffffff&#34;> onPlusReady</span><span style&#61;&#34;color:#ffffff&#34;>()</span> <span style&#61;&#34;color:#ffffff&#34;>{</span><span style&#61;&#34;color:#ffffff&#34;>
        plus</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>proximity</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>watchProximity</span><span style&#61;&#34;color:#ffffff&#34;>(</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>function</strong></span> <span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> d </span><span style&#61;&#34;color:#ffffff&#34;>)</span> <span style&#61;&#34;color:#ffffff&#34;>{</span><span style&#61;&#34;color:#ffffff&#34;>
                document</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>getElementById</span><span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffa0a0&#34;>&#34;inf&#34;</span><span style&#61;&#34;color:#ffffff&#34;>).</span><span style&#61;&#34;color:#ffffff&#34;>innerText</span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>&#34;Proximity: &#34;</span><span style&#61;&#34;color:#ffffff&#34;>&#43;</span><span style&#61;&#34;color:#ffffff&#34;>d</span><span style&#61;&#34;color:#ffffff&#34;>;</span>
        <span style&#61;&#34;color:#ffffff&#34;>},</span> <span style&#61;&#34;color:#f0e68c&#34;><strong>function</strong></span> <span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> e </span><span style&#61;&#34;color:#ffffff&#34;>)</span> <span style&#61;&#34;color:#ffffff&#34;>{</span><span style&#61;&#34;color:#ffffff&#34;>
                alert</span><span style&#61;&#34;color:#ffffff&#34;>(</span> <span style&#61;&#34;color:#ffa0a0&#34;>&#34;Error: &#34;</span> <span style&#61;&#34;color:#ffffff&#34;>&#43;</span><span style&#61;&#34;color:#ffffff&#34;> e</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>message </span><span style&#61;&#34;color:#ffffff&#34;>);</span>
        <span style&#61;&#34;color:#ffffff&#34;>}</span> <span style&#61;&#34;color:#ffffff&#34;>);</span>
<span style&#61;&#34;color:#ffffff&#34;>}</span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong></script></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong></head></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong><body</strong></span> <span style&#61;&#34;color:#f0e68c&#34;><strong>></strong></span><span style&#61;&#34;color:#ffffff&#34;>
                Proximity watch</span><span style&#61;&#34;color:#f0e68c&#34;><strong><br/></strong></span>
                <span style&#61;&#34;color:#f0e68c&#34;><strong><span</strong></span> <span style&#61;&#34;color:#bdb76b&#34;><strong>id</strong></span><span style&#61;&#34;color:#ffffff&#34;>&#61;</span><span style&#61;&#34;color:#ffa0a0&#34;>&#34;inf&#34;</span><span style&#61;&#34;color:#f0e68c&#34;><strong>></span></strong></span>
        <span style&#61;&#34;color:#f0e68c&#34;><strong></body></strong></span>
<span style&#61;&#34;color:#f0e68c&#34;><strong></html></strong></span>
                                </code></span></span></code></pre>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><ahref="https://uniapp.dcloud.io/use-html5plus">uni-app使用plus注意事项</a></span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_13-->clearWatch</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">关闭监听设备接近距离变化</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
<span style&#61;&#34;color:#f0e68c&#34;><strong>void</strong></span><span style&#61;&#34;color:#ffffff&#34;> plus</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>proximity</span><span style&#61;&#34;color:#ffffff&#34;>.</span><span style&#61;&#34;color:#ffffff&#34;>clearWatch</span><span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> watchId </span><span style&#61;&#34;color:#ffffff&#34;>);</span>
                                </code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数&#xff1a;</span></strong></span></h2>
<ul><li>watchId: <em>( Number ) 必选</em> <p style="margin-left:0;"><span style="color:#474747;">需要取消的距离监听器标识&#xff0c;调用watchProximity方法的返回值。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值&#xff1a;</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">平台支持&#xff1a;</span></strong></span></h2>
<ul><li>Android - 2.2&#43; (支持) : <p style="margin-left:0;"><span style="color:#474747;">支持</span></p> </li><li>iOS - 4.3&#43; (支持) : <p style="margin-left:0;"><span style="color:#474747;">支持</span></p> </li></ul>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_14-->ProximitySuccessCallback</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">获取设备接近距离信息成功的回调函数</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
<span style&#61;&#34;color:#f0e68c&#34;><strong>void</strong></span><span style&#61;&#34;color:#ffffff&#34;> onSuccess</span><span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> distance </span><span style&#61;&#34;color:#ffffff&#34;>)</span> <span style&#61;&#34;color:#ffffff&#34;>{</span>
        <span style&#61;&#34;color:#87ceeb&#34;>// Get distance success code.</span>
<span style&#61;&#34;color:#ffffff&#34;>}</span>
                                </code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数&#xff1a;</span></strong></span></h2>
<ul><li>distance: <em>( Number ) 必选 </em>设备接近距离 <p style="margin-left:0;"><span style="color:#474747;">设备接近距离传感器获取的距离值&#xff0c;单位为厘米。如果感应器无法获取准确的距离值&#xff0c;则在接近设备时返回0&#xff0c;否则返回Infinity。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值&#xff1a;</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_15-->ProximityErrorCallback</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">获取设备接近距离信息失败的回调函数</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style&#61;&#34;background-color:#333333&#34;><span style&#61;&#34;color:#474747&#34;><code>
<span style&#61;&#34;color:#f0e68c&#34;><strong>void</strong></span><span style&#61;&#34;color:#ffffff&#34;> onError</span><span style&#61;&#34;color:#ffffff&#34;>(</span><span style&#61;&#34;color:#ffffff&#34;> error </span><span style&#61;&#34;color:#ffffff&#34;>)</span> <span style&#61;&#34;color:#ffffff&#34;>{</span>
        <span style&#61;&#34;color:#87ceeb&#34;>// Get distance error code.</span>
<span style&#61;&#34;color:#ffffff&#34;>}</span>
                                </code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数&#xff1a;</span></strong></span></h2>
<ul><li>error: <em>( Exception ) 必选 </em>失败信息 <p style="margin-left:0;"></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值&#xff1a;</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
                </div>
      </div>
      <div id="treeSkill"></div>
页: [1]
查看完整版本: Proximity模块管理设备距离传感器,可获取当前设备的接近距离信息,通过plus.proximit ...