当前位置:   article > 正文

fingerprint模块管理指纹识别_plus.fingerprint.authenticate

plus.fingerprint.authenticate

Android平台6.0及以上系统支持,仅适配Google官方指纹识别的标准接口的设备。

方法:

对象:

回调方法:

权限:

5+功能模块(permissions)

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#ffffff">{</span>
  3. <span style="color:#87ceeb">// ...</span>
  4. <span style="color:#ffa0a0">"permissions"</span><span style="color:#ffffff">:{</span>
  5. <span style="color:#87ceeb">// ...</span>
  6. <span style="color:#ffa0a0">"Fingerprint"</span><span style="color:#ffffff">:</span> <span style="color:#ffffff">{</span>
  7. <span style="color:#ffa0a0">"description"</span><span style="color:#ffffff">:</span> <span style="color:#ffa0a0">"指纹识别"</span>
  8. <span style="color:#ffffff">}</span>
  9. <span style="color:#ffffff">}</span>
  10. <span style="color:#ffffff">}</span>
  11. </code></span></span>

isSupport

当前设备环境是否支持指纹识别

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>boolean</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isSupport</span><span style="color:#ffffff">();</span>
  3. </code></span></span>

说明:

目前还有很多设备没有指纹识别模块,需要调用此方法判断是否可使用指纹识别功能。

参数:

返回值:

Boolean : 设备支持指纹识别则返回true,否则返回false。

示例:

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#cccccc"><!DOCTYPE html></span>
  3. <span style="color:#f0e68c"><strong><html></strong></span>
  4. <span style="color:#f0e68c"><strong><head></strong></span>
  5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
  6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
  7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
  8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
  9. <span style="color:#87ceeb">// H5 plus事件处理</span>
  10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
  11. <span style="color:#87ceeb">// 判断设备是否支持指纹识别</span>
  12. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  13. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getElementById</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'result'</span><span style="color:#ffffff">).</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isSupport</span><span style="color:#ffffff">()?</span><span style="color:#ffa0a0">'支持'</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'不支持'</span><span style="color:#ffffff">;</span>
  14. <span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  15. console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">"请更新版本"</span><span style="color:#ffffff">);</span>
  16. <span style="color:#ffffff">}</span>
  17. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  18. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
  19. <span style="color:#f0e68c"><strong></script></strong></span>
  20. <span style="color:#f0e68c"><strong></head></strong></span>
  21. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
  22. 当前设备环境是否支持指纹识别:
  23. </span><span style="color:#f0e68c"><strong><br/></strong></span>
  24. <span style="color:#f0e68c"><strong><p</strong></span> <span style="color:#bdb76b"><strong>id</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"result"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">...</span><span style="color:#f0e68c"><strong></p></strong></span>
  25. <span style="color:#f0e68c"><strong></body></strong></span>
  26. <span style="color:#f0e68c"><strong></html></strong></span>
  27. </code></span></span>

uni-app使用plus注意事项

isKeyguardSecure

当前设备是否设置密码锁屏

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>boolean</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isKeyguardSecure</span><span style="color:#ffffff">();</span>
  3. </code></span></span>

说明:

如果设备没有设置密码锁屏,则无法使用指纹识别功能,建议调用指纹识别前先使用此接口检查。 调用plus.fingerprint.authenticate会返回失败。

参数:

返回值:

Boolean : 设备已设置密码锁屏则返回true,否则返回false。

平台支持:

  • Android (支持) :

    要求设置密码锁屏才可以使用指纹识别,如果没有设置密码锁屏应该提示用户进行设置。

  • iOS (不支持) :

    不支持此功能,返回true。

示例:

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#cccccc"><!DOCTYPE html></span>
  3. <span style="color:#f0e68c"><strong><html></strong></span>
  4. <span style="color:#f0e68c"><strong><head></strong></span>
  5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
  6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
  7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
  8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
  9. <span style="color:#87ceeb">// H5 plus事件处理</span>
  10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
  11. <span style="color:#87ceeb">// 判断设备是否设置密码锁屏</span>
  12. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  13. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getElementById</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'result'</span><span style="color:#ffffff">).</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isKeyguardSecure</span><span style="color:#ffffff">()?</span><span style="color:#ffa0a0">'是'</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'否'</span><span style="color:#ffffff">;</span>
  14. <span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  15. console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">"请更新版本"</span><span style="color:#ffffff">);</span>
  16. <span style="color:#ffffff">}</span>
  17. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  18. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
  19. <span style="color:#f0e68c"><strong></script></strong></span>
  20. <span style="color:#f0e68c"><strong></head></strong></span>
  21. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
  22. 当前设备是否设置密码锁屏:
  23. </span><span style="color:#f0e68c"><strong><br/></strong></span>
  24. <span style="color:#f0e68c"><strong><p</strong></span> <span style="color:#bdb76b"><strong>id</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"result"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">...</span><span style="color:#f0e68c"><strong></p></strong></span>
  25. <span style="color:#f0e68c"><strong></body></strong></span>
  26. <span style="color:#f0e68c"><strong></html></strong></span>
  27. </code></span></span>

uni-app使用plus注意事项

isEnrolledFingerprints

当前设备是否已经录入指纹

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>boolean</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isEnrolledFingerprints</span><span style="color:#ffffff">();</span>
  3. </code></span></span>

说明:

如果设备没有录入指纹,则无法使用指纹识别功能,建议调用指纹识别前先使用此接口检查。 调用plus.fingerprint.authenticate会返回失败。

参数:

返回值:

Boolean : 设备已经录入指纹则返回true,否则返回false。

示例:

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#cccccc"><!DOCTYPE html></span>
  3. <span style="color:#f0e68c"><strong><html></strong></span>
  4. <span style="color:#f0e68c"><strong><head></strong></span>
  5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
  6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
  7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
  8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
  9. <span style="color:#87ceeb">// H5 plus事件处理</span>
  10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
  11. <span style="color:#87ceeb">// 判断设备是否已经录入指纹</span>
  12. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  13. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getElementById</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'result'</span><span style="color:#ffffff">).</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isEnrolledFingerprints</span><span style="color:#ffffff">()?</span><span style="color:#ffa0a0">'是'</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'否'</span><span style="color:#ffffff">;</span>
  14. <span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  15. console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">"请更新版本"</span><span style="color:#ffffff">);</span>
  16. <span style="color:#ffffff">}</span>
  17. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  18. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
  19. <span style="color:#f0e68c"><strong></script></strong></span>
  20. <span style="color:#f0e68c"><strong></head></strong></span>
  21. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
  22. 当前设备是否已经录入指纹:
  23. </span><span style="color:#f0e68c"><strong><br/></strong></span>
  24. <span style="color:#f0e68c"><strong><p</strong></span> <span style="color:#bdb76b"><strong>id</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"result"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">...</span><span style="color:#f0e68c"><strong></p></strong></span>
  25. <span style="color:#f0e68c"><strong></body></strong></span>
  26. <span style="color:#f0e68c"><strong></html></strong></span>
  27. </code></span></span>

uni-app使用plus注意事项

authenticate

指纹识别认证

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">authenticate</span><span style="color:#ffffff">(</span><span style="color:#ffffff">successCB</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> errorCB</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> options</span><span style="color:#ffffff">);</span>
  3. </code></span></span>

说明:

用户可以开始输入指纹进行识别,如果认证成功则触发successCB回调,识别失败则触发errorCB回调返回错误信息。

参数:

  • successCB: FingerprintSuccessCallback ) 必选 识别认证成功回调

    指纹识别操作认证成功时调用。

  • errorCB: FingerprintErrorCallback ) 必选

    指纹识别操作认证失败时调用,每次指纹识别错误都会触发一次错误回调。

  • options: AuthenticateOptions ) 可选 识别认证参数

    用于设置指纹识别界面显示的提示信息等。

返回值:

void : 无

平台支持:

  • Android (支持) :

    指纹识别过程中不会弹出任何界面,需要开发者根据业务需求弹出提示信息。

  • iOS (支持) :

    指纹识别过程中会弹出系统界面。

示例:

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#cccccc"><!DOCTYPE html></span>
  3. <span style="color:#f0e68c"><strong><html></strong></span>
  4. <span style="color:#f0e68c"><strong><head></strong></span>
  5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
  6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
  7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
  8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
  9. <span style="color:#87ceeb">// H5 plus事件处理</span>
  10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
  11. <span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> result </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getElementById</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'result'</span><span style="color:#ffffff">);</span>
  12. <span style="color:#87ceeb">// 检查是否支持指纹识别</span>
  13. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
  14. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(!</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isSupport</span><span style="color:#ffffff">())</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  15. result</span><span style="color:#ffffff">.</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'此设备不支持指纹识别'</span><span style="color:#ffffff">;</span>
  16. <span style="color:#f0e68c"><strong>return</strong></span><span style="color:#ffffff">;</span>
  17. <span style="color:#ffffff">}</span>
  18. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(!</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isKeyguardSecure</span><span style="color:#ffffff">())</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  19. result</span><span style="color:#ffffff">.</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'此设备未设置密码锁屏,无法使用指纹识别'</span><span style="color:#ffffff">;</span>
  20. <span style="color:#f0e68c"><strong>return</strong></span><span style="color:#ffffff">;</span>
  21. <span style="color:#ffffff">}</span>
  22. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(!</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">isEnrolledFingerprints</span><span style="color:#ffffff">())</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  23. result</span><span style="color:#ffffff">.</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'此设备未录入指纹,请到设置中开启'</span><span style="color:#ffffff">;</span>
  24. <span style="color:#f0e68c"><strong>return</strong></span><span style="color:#ffffff">;</span>
  25. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  26. result</span><span style="color:#ffffff">.</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'此设备支持指纹识别'</span><span style="color:#ffffff">;</span>
  27. <span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  28. result</span><span style="color:#ffffff">.</span><span style="color:#ffffff">innerText </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'当前环境不支持指纹识别API,请更新到最新版本'</span><span style="color:#ffffff">;</span>
  29. <span style="color:#ffffff">}</span>
  30. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  31. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
  32. <span style="color:#87ceeb">// 指纹识别认证 </span>
  33. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> fingerpring</span><span style="color:#ffffff">()</span> <span style="color:#ffffff">{</span>
  34. <span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> waiting </span><span style="color:#ffffff">=</span> <span style="color:#f0e68c"><strong>null</strong></span><span style="color:#ffffff">;</span><span style="color:#ffffff">
  35. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">authenticate</span><span style="color:#ffffff">(</span><span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span><span style="color:#ffffff">
  36. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">closeWaiting</span><span style="color:#ffffff">();</span><span style="color:#87ceeb">//兼容Android平台关闭等待框</span><span style="color:#ffffff">
  37. alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别成功'</span><span style="color:#ffffff">);</span>
  38. <span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">){</span>
  39. <span style="color:#f0e68c"><strong>switch</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
  40. <span style="color:#f0e68c"><strong>case</strong></span><span style="color:#ffffff"> e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">AUTHENTICATE_MISMATCH</span><span style="color:#ffffff">:</span><span style="color:#ffffff">
  41. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">toast</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹匹配失败,请重新输入'</span><span style="color:#ffffff">);</span>
  42. <span style="color:#f0e68c"><strong>break</strong></span><span style="color:#ffffff">;</span>
  43. <span style="color:#f0e68c"><strong>case</strong></span><span style="color:#ffffff"> e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">AUTHENTICATE_OVERLIMIT</span><span style="color:#ffffff">:</span><span style="color:#ffffff">
  44. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">closeWaiting</span><span style="color:#ffffff">();</span><span style="color:#87ceeb">//兼容Android平台关闭等待框</span><span style="color:#ffffff">
  45. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别失败次数超出限制,请使用其它方式进行认证'</span><span style="color:#ffffff">);</span>
  46. <span style="color:#f0e68c"><strong>break</strong></span><span style="color:#ffffff">;</span>
  47. <span style="color:#f0e68c"><strong>default</strong></span><span style="color:#ffffff">:</span><span style="color:#ffffff">
  48. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">closeWaiting</span><span style="color:#ffffff">();</span><span style="color:#87ceeb">//兼容Android平台关闭等待框</span><span style="color:#ffffff">
  49. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别失败('</span><span style="color:#ffffff">+</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">+</span><span style="color:#ffa0a0">'),请重试'</span><span style="color:#ffffff">);</span>
  50. <span style="color:#f0e68c"><strong>break</strong></span><span style="color:#ffffff">;</span>
  51. <span style="color:#ffffff">}</span>
  52. <span style="color:#ffffff">});</span>
  53. <span style="color:#87ceeb">// Android平台弹出等待提示框 </span>
  54. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'Android'</span><span style="color:#ffffff">==</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">os</span><span style="color:#ffffff">.</span><span style="color:#ffffff">name</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  55. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">showWaiting</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别中...'</span><span style="color:#ffffff">);</span>
  56. <span style="color:#ffffff">}</span>
  57. <span style="color:#ffffff">}</span>
  58. <span style="color:#f0e68c"><strong></script></strong></span>
  59. <span style="color:#f0e68c"><strong></head></strong></span>
  60. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
  61. 指纹识别认证:
  62. </span><span style="color:#f0e68c"><strong><br/></strong></span>
  63. <span style="color:#f0e68c"><strong><p</strong></span> <span style="color:#bdb76b"><strong>id</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"result"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">...</span><span style="color:#f0e68c"><strong></p></strong></span>
  64. <span style="color:#f0e68c"><strong><br/></strong></span>
  65. <span style="color:#f0e68c"><strong><button</strong></span> <span style="color:#bdb76b"><strong>onclick</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"</span><span style="color:#ffffff">fingerpring</span><span style="color:#ffffff">()</span><span style="color:#ffa0a0">"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">指纹识别</span><span style="color:#f0e68c"><strong></button></strong></span>
  66. <span style="color:#f0e68c"><strong></body></strong></span>
  67. <span style="color:#f0e68c"><strong></html></strong></span>
  68. </code></span></span>

uni-app使用plus注意事项

cancel

取消指纹识别认证

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">cancel</span><span style="color:#ffffff">();</span>
  3. </code></span></span>

说明:

取消当前正在处理的指纹识别认证操作。 如果当前没有进行指纹识别则不进行任何操作;如果当前正在进行指纹识别则触发错误回调(错误码为“CANCEL”)。

参数:

返回值:

void : 无

示例:

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#cccccc"><!DOCTYPE html></span>
  3. <span style="color:#f0e68c"><strong><html></strong></span>
  4. <span style="color:#f0e68c"><strong><head></strong></span>
  5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
  6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
  7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
  8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
  9. <span style="color:#87ceeb">// H5 plus事件处理</span>
  10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
  11. <span style="color:#87ceeb">// 自动调用指纹识别</span><span style="color:#ffffff">
  12. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">authenticate</span><span style="color:#ffffff">(</span><span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span><span style="color:#ffffff">
  13. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">toast</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别成功'</span><span style="color:#ffffff">);</span>
  14. <span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
  15. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别失败('</span><span style="color:#ffffff">+</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">+</span><span style="color:#ffa0a0">')'</span><span style="color:#ffffff">);</span>
  16. <span style="color:#ffffff">});</span>
  17. <span style="color:#87ceeb">// iOS平台指纹识别提示框会阻塞界面操作,定时调用</span>
  18. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'iOS'</span><span style="color:#ffffff">==</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">os</span><span style="color:#ffffff">.</span><span style="color:#ffffff">name</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  19. setTimeout</span><span style="color:#ffffff">(</span><span style="color:#ffffff">cancelFingerpring</span><span style="color:#ffffff">,</span> <span style="color:#cd5c5c">10000</span><span style="color:#ffffff">);</span>
  20. <span style="color:#ffffff">}</span>
  21. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  22. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
  23. <span style="color:#87ceeb">// 取消指纹识别</span>
  24. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> cancelFingerpring</span><span style="color:#ffffff">()</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
  25. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">cancel</span><span style="color:#ffffff">();</span>
  26. <span style="color:#ffffff">}</span>
  27. <span style="color:#f0e68c"><strong></script></strong></span>
  28. <span style="color:#f0e68c"><strong></head></strong></span>
  29. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
  30. 取消指纹识别认证
  31. </span><span style="color:#f0e68c"><strong><br/></strong></span>
  32. <span style="color:#f0e68c"><strong><button</strong></span> <span style="color:#bdb76b"><strong>onclick</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"</span><span style="color:#ffffff">cancelFingerpring</span><span style="color:#ffffff">()</span><span style="color:#ffa0a0">"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">取消识别</span><span style="color:#f0e68c"><strong></button></strong></span>
  33. <span style="color:#f0e68c"><strong><br/></strong></span><span style="color:#ffffff">
  34. 注意:iOS平台10秒后自动取消
  35. </span><span style="color:#f0e68c"><strong></body></strong></span>
  36. <span style="color:#f0e68c"><strong></html></strong></span>
  37. </code></span></span>

uni-app使用plus注意事项

AuthenticateOptions

JSON对象,指纹识别认证参数

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>interface</strong></span> <span style="color:#98fb98">AuthenticateOptions</span> <span style="color:#ffffff">{</span>
  3. <span style="color:#f0e68c"><strong>readonly</strong></span><span style="color:#ffffff"> attribute </span><span style="color:#98fb98">String</span><span style="color:#ffffff"> message</span><span style="color:#ffffff">;</span>
  4. <span style="color:#ffffff">}</span>
  5. </code></span></span>

说明:

用于设置指纹识别认证界面显示的提示信息等。

属性:

  • message: (String 类型 )在指纹识别过程中显示在界面上的提示信息

    如果指纹识别认证过程中不显示提示框,则不显示此信息。

    平台支持

    • Android - (不支持) :

      指纹识别认证过程中不显示提示框,需要开发者自定义显示。

    • iOS - (支持) :

      指纹识别认证过程中显示系统提示框,在提示框中显示此信息(默认显示信息为空字符串)。

    1. <span style="background-color:#333333"><code>
    2. <span style="color:#cccccc"><!DOCTYPE html></span>
    3. <span style="color:#f0e68c"><strong><html></strong></span>
    4. <span style="color:#f0e68c"><strong><head></strong></span>
    5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
    6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
    7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
    8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
    9. <span style="color:#87ceeb">// H5 plus事件处理</span>
    10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
    11. <span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> waiting </span><span style="color:#ffffff">=</span> <span style="color:#f0e68c"><strong>null</strong></span><span style="color:#ffffff">;</span>
    12. <span style="color:#87ceeb">// 自动调用指纹识别</span><span style="color:#ffffff">
    13. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">authenticate</span><span style="color:#ffffff">(</span><span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span><span style="color:#ffffff">
    14. waiting</span><span style="color:#ffffff">&&(</span><span style="color:#ffffff">waiting</span><span style="color:#ffffff">.</span><span style="color:#ffffff">onclose</span><span style="color:#ffffff">=</span><span style="color:#f0e68c"><strong>null</strong></span><span style="color:#ffffff">);</span><span style="color:#ffffff">
    15. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">closeWaiting</span><span style="color:#ffffff">();</span><span style="color:#ffffff">
    16. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别成功'</span><span style="color:#ffffff">);</span>
    17. <span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">){</span>
    18. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">AUTHENTICATE_MISMATCH </span><span style="color:#ffffff">==</span><span style="color:#ffffff"> e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
    19. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">toast</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹匹配失败,请重新输入'</span><span style="color:#ffffff">);</span>
    20. <span style="color:#f0e68c"><strong>return</strong></span><span style="color:#ffffff">;</span>
    21. <span style="color:#ffffff">}</span><span style="color:#ffffff">
    22. waiting</span><span style="color:#ffffff">&&(</span><span style="color:#ffffff">waiting</span><span style="color:#ffffff">.</span><span style="color:#ffffff">onclose</span><span style="color:#ffffff">=</span><span style="color:#f0e68c"><strong>null</strong></span><span style="color:#ffffff">);</span><span style="color:#ffffff">
    23. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">closeWaiting</span><span style="color:#ffffff">();</span><span style="color:#ffffff">
    24. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别失败('</span><span style="color:#ffffff">+</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">+</span><span style="color:#ffa0a0">')'</span><span style="color:#ffffff">);</span>
    25. <span style="color:#ffffff">},{</span><span style="color:#ffffff">
    26. message</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'通过Home键验证已有手机指纹'</span>
    27. <span style="color:#ffffff">});</span>
    28. <span style="color:#87ceeb">// Android平台使用自定义等待框显示 </span>
    29. <span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">"Android"</span><span style="color:#ffffff">==</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">os</span><span style="color:#ffffff">.</span><span style="color:#ffffff">name</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
    30. waiting </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">showWaiting</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'验证已有手机指纹'</span><span style="color:#ffffff">,{</span><span style="color:#ffffff">width</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'196px'</span><span style="color:#ffffff">,</span><span style="color:#ffffff">height</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'196px'</span><span style="color:#ffffff">,</span><span style="color:#ffffff">padding</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'16px'</span><span style="color:#ffffff">,</span><span style="color:#ffffff">loading</span><span style="color:#ffffff">:{</span><span style="color:#ffffff">height</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'96px'</span><span style="color:#ffffff">,</span><span style="color:#ffffff">icon</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'fp.png'</span><span style="color:#ffffff">},</span><span style="color:#ffffff">background</span><span style="color:#ffffff">:</span><span style="color:#ffa0a0">'rgba(0,0,0,0.3)'</span><span style="color:#ffffff">});</span><span style="color:#ffffff">
    31. waiting</span><span style="color:#ffffff">.</span><span style="color:#ffffff">onclose </span><span style="color:#ffffff">=</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span><span style="color:#ffffff">
    32. waiting </span><span style="color:#ffffff">=</span> <span style="color:#f0e68c"><strong>null</strong></span><span style="color:#ffffff">;</span><span style="color:#ffffff">
    33. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">cancel</span><span style="color:#ffffff">();</span>
    34. <span style="color:#ffffff">}</span>
    35. <span style="color:#ffffff">}</span>
    36. <span style="color:#ffffff">}</span><span style="color:#ffffff">
    37. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
    38. <span style="color:#f0e68c"><strong></script></strong></span>
    39. <span style="color:#f0e68c"><strong></head></strong></span>
    40. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
    41. 指纹识别认证
    42. </span><span style="color:#f0e68c"><strong></body></strong></span>
    43. <span style="color:#f0e68c"><strong></html></strong></span>
    44. </code></span>

FingerprintError

JSON对象,指纹识别错误信息

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>interface</strong></span> <span style="color:#98fb98">FingerprintError</span> <span style="color:#ffffff">{</span>
  3. <span style="color:#f0e68c"><strong>const</strong></span> <span style="color:#98fb98">Number</span><span style="color:#ffffff"> UNSUPPORT </span><span style="color:#ffffff">=</span> <span style="color:#cd5c5c">1</span><span style="color:#ffffff">;</span>
  4. <span style="color:#f0e68c"><strong>const</strong></span> <span style="color:#98fb98">Number</span><span style="color:#ffffff"> KEYGUARD_INSECURE </span><span style="color:#ffffff">=</span> <span style="color:#cd5c5c">2</span><span style="color:#ffffff">;</span>
  5. <span style="color:#f0e68c"><strong>const</strong></span> <span style="color:#98fb98">Number</span><span style="color:#ffffff"> FINGERPRINT_UNENROLLED </span><span style="color:#ffffff">=</span> <span style="color:#cd5c5c">3</span><span style="color:#ffffff">;</span>
  6. <span style="color:#f0e68c"><strong>const</strong></span> <span style="color:#98fb98">Number</span><span style="color:#ffffff"> AUTHENTICATE_MISMATCH </span><span style="color:#ffffff">=</span> <span style="color:#cd5c5c">4</span><span style="color:#ffffff">;</span>
  7. <span style="color:#f0e68c"><strong>const</strong></span> <span style="color:#98fb98">Number</span><span style="color:#ffffff"> AUTHENTICATE_OVERLIMIT </span><span style="color:#ffffff">=</span> <span style="color:#cd5c5c">5</span><span style="color:#ffffff">;</span>
  8. <span style="color:#f0e68c"><strong>const</strong></span> <span style="color:#98fb98">Number</span><span style="color:#ffffff"> CANCEL </span><span style="color:#ffffff">=</span> <span style="color:#cd5c5c">6</span><span style="color:#ffffff">;</span>
  9. <span style="color:#f0e68c"><strong>const</strong></span> <span style="color:#98fb98">Number</span><span style="color:#ffffff"> UNKNOWN_ERROR </span><span style="color:#ffffff">=</span> <span style="color:#cd5c5c">7</span><span style="color:#ffffff">;</span>
  10. <span style="color:#f0e68c"><strong>readonly</strong></span><span style="color:#ffffff"> attribute </span><span style="color:#98fb98">Number</span><span style="color:#ffffff"> code</span><span style="color:#ffffff">;</span>
  11. <span style="color:#f0e68c"><strong>readonly</strong></span><span style="color:#ffffff"> attribute </span><span style="color:#98fb98">String</span><span style="color:#ffffff"> message</span><span style="color:#ffffff">;</span>
  12. <span style="color:#ffffff">}</span>
  13. </code></span></span>

常量:

  • UNSUPPORT: (Number 类型 )不支持指纹识别

    当前设备不支持指纹识别功能时返回此错误,错误代码常量值为1。

  • KEYGUARD_INSECURE: (Number 类型 )设备未设置密码锁屏

    当前设备为设置密码锁屏导致无法使用指纹识别功能时返回此错误,错误代码常量值为2。

  • FINGERPRINT_UNENROLLED: (Number 类型 )未录入指纹识别

    当前设备未录入指纹导致无法使用指纹识别功能时返回此错误,错误代码常量值为3。

  • AUTHENTICATE_MISMATCH: (Number 类型 )指纹识别不匹配

    用户指纹识别认证不通过时返回此错误,错误代码常量值为4。 用户每次尝试指纹识别认证未通过都会触发此错误,此时还可以继续识别认证。

  • AUTHENTICATE_OVERLIMIT: (Number 类型 )指纹识别次数超过限制

    用户多次指纹识别认证不通过时返回此错误,错误代码常量值为5。 通常出现此错误后系统会锁定一段时间禁止使用指纹识别,如果再次调用指纹识别认证会立即返回此错误,因此出现此错误时应该提示用户使用其它方式进行认证。

  • CANCEL: (Number 类型 )取消指纹识别

    用户取消指纹识别认证时返回此错误,错误代码常量值为6。

  • UNKNOWN_ERROR: (Number 类型 )未知错误

    其它未知错误,错误代码常量值为7。

属性:

  • code: (Number 类型 )错误代码

    取值范围为FingerprintError对象的错误常量值。

  • message: (String 类型 )错误描述信息

    详细错误描述信息。

FingerprintSuccessCallback

指纹识别认证成功回调函数

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> onSuccess</span><span style="color:#ffffff">()</span> <span style="color:#ffffff">{</span>
  3. <span style="color:#87ceeb">// Authenticate success code.</span>
  4. <span style="color:#ffffff">}</span>
  5. </code></span></span>

参数:

返回值:

void : 无

示例:

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#cccccc"><!DOCTYPE html></span>
  3. <span style="color:#f0e68c"><strong><html></strong></span>
  4. <span style="color:#f0e68c"><strong><head></strong></span>
  5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
  6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
  7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
  8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
  9. <span style="color:#87ceeb">// H5 plus事件处理</span>
  10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
  11. <span style="color:#87ceeb">// 自动调用指纹识别</span><span style="color:#ffffff">
  12. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">authenticate</span><span style="color:#ffffff">(</span><span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span><span style="color:#ffffff">
  13. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别成功'</span><span style="color:#ffffff">);</span>
  14. <span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
  15. console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别失败('</span><span style="color:#ffffff">+</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">+</span><span style="color:#ffa0a0">')'</span><span style="color:#ffffff">);</span>
  16. <span style="color:#ffffff">});</span>
  17. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  18. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
  19. <span style="color:#f0e68c"><strong></script></strong></span>
  20. <span style="color:#f0e68c"><strong></head></strong></span>
  21. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
  22. 指纹识别认证
  23. </span><span style="color:#f0e68c"><strong></body></strong></span>
  24. <span style="color:#f0e68c"><strong></html></strong></span>
  25. </code></span></span>

uni-app使用plus注意事项

FingerprintErrorCallback

指纹识别认证失败的回调函数

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#f0e68c"><strong>function</strong></span> <span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> onError</span><span style="color:#ffffff">(</span><span style="color:#98fb98">FingerprintError</span><span style="color:#ffffff"> error</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
  3. <span style="color:#87ceeb">// Handle error</span>
  4. <span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> code </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> error</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">;</span> <span style="color:#87ceeb">// 错误编码</span>
  5. <span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> message </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> error</span><span style="color:#ffffff">.</span><span style="color:#ffffff">message</span><span style="color:#ffffff">;</span> <span style="color:#87ceeb">// 错误描述信息</span>
  6. <span style="color:#ffffff">}</span>
  7. </code></span></span>

参数:

  • error: FingerprintError ) 必选 获取加速度操作的错误信息

    可通过error.code(Number类型)获取错误编码; 可通过error.message(String类型)获取错误描述信息。

返回值:

void : 无

示例:

  1. <span style="background-color:#333333"><span style="color:#474747"><code>
  2. <span style="color:#cccccc"><!DOCTYPE html></span>
  3. <span style="color:#f0e68c"><strong><html></strong></span>
  4. <span style="color:#f0e68c"><strong><head></strong></span>
  5. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
  6. <span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
  7. <span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Fingerprint Example</span><span style="color:#f0e68c"><strong></title></strong></span>
  8. <span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
  9. <span style="color:#87ceeb">// H5 plus事件处理</span>
  10. <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
  11. <span style="color:#87ceeb">// 自动调用指纹识别</span><span style="color:#ffffff">
  12. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">fingerprint</span><span style="color:#ffffff">.</span><span style="color:#ffffff">authenticate</span><span style="color:#ffffff">(</span><span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span><span style="color:#ffffff">
  13. console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别成功'</span><span style="color:#ffffff">);</span>
  14. <span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">){</span>
  15. <span style="color:#f0e68c"><strong>switch</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
  16. <span style="color:#f0e68c"><strong>case</strong></span><span style="color:#ffffff"> e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">AUTHENTICATE_MISMATCH</span><span style="color:#ffffff">:</span><span style="color:#ffffff">
  17. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹匹配失败,请重新输入'</span><span style="color:#ffffff">);</span>
  18. <span style="color:#f0e68c"><strong>break</strong></span><span style="color:#ffffff">;</span>
  19. <span style="color:#f0e68c"><strong>case</strong></span><span style="color:#ffffff"> e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">AUTHENTICATE_OVERLIMIT</span><span style="color:#ffffff">:</span><span style="color:#ffffff">
  20. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别失败次数超出限制,请使用其它方式进行认证'</span><span style="color:#ffffff">);</span>
  21. <span style="color:#f0e68c"><strong>break</strong></span><span style="color:#ffffff">;</span>
  22. <span style="color:#f0e68c"><strong>default</strong></span><span style="color:#ffffff">:</span><span style="color:#ffffff">
  23. plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">nativeUI</span><span style="color:#ffffff">.</span><span style="color:#ffffff">alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'指纹识别失败('</span><span style="color:#ffffff">+</span><span style="color:#ffffff">e</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">+</span><span style="color:#ffa0a0">'),请重试'</span><span style="color:#ffffff">);</span>
  24. <span style="color:#f0e68c"><strong>break</strong></span><span style="color:#ffffff">;</span>
  25. <span style="color:#ffffff">}</span>
  26. <span style="color:#ffffff">});</span>
  27. <span style="color:#ffffff">}</span><span style="color:#ffffff">
  28. document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
  29. <span style="color:#f0e68c"><strong></script></strong></span>
  30. <span style="color:#f0e68c"><strong></head></strong></span>
  31. <span style="color:#f0e68c"><strong><body</strong></span> <span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">
  32. 指纹识别认证
  33. </span><span style="color:#f0e68c"><strong></body></strong></span>
  34. <span style="color:#f0e68c"><strong></html></strong></span></code></span></span>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/222615
推荐阅读
相关标签
  

闽ICP备14008679号