
Adding biometric authentication to a WebViewGold iOS app is surprisingly straightforward. You do not need to write a single line of Swift. The entire flow can be controlled from an HTML button inside your web content. This article explains how to trigger Face ID directly from that button using the built-in JavaScript bridge.
How WebViewGold Enables Native Features from HTML
WebViewGold wraps your website inside a native iOS shell and exposes a set of native features through a JavaScript bridge. Face ID is one of those exposed features. When a user taps a button in your HTML page, you can send a message to the native layer that initiates the Face ID prompt. The native code is already written and bundled inside WebViewGold, so you only work with JavaScript.
Setting Up Your HTML Button
Place a button anywhere in your HTML page. Give it a unique id so you can attach an event listener from your JavaScript code.
<button id="faceid-btn">Unlock with Face ID</button>
Sending the Face ID Request from JavaScript
In your JavaScript file or inline script, add a click event listener to that button. Inside the listener, call the WebViewGold Face ID handler through the standard WKWebView message handler interface. WebViewGold predefines the name faceID for this purpose.
document.getElementById('faceid-btn').addEventListener('click', function() {
window.webkit.messageHandlers.faceID.postMessage('Please authenticate to access this feature');
});
Handling the Authentication Result
When the user completes the Face ID prompt, WebViewGold automatically calls a global JavaScript function named faceIDCallback. The function receives two arguments: a boolean success flag and a message string describing the result. You can define this function anywhere in your web page to react to success or failure.
function faceIDCallback(success, message) {
if (success) {
// Proceed with the protected action
document.getElementById('status').innerText = 'Authentication succeeded';
} else {
// Handle the failure or cancellation
document.getElementById('status').innerText = message;
}
}
Add a simple element with id=”status” to display the result if you wish.
A Note on Android and Cross-Platform Development
While this guide focuses on iOS, WebViewGold also provides a quick and simple solution to convert websites into apps for Android easily. The same philosophy of exposing native features through a JavaScript bridge applies to the Android version, making it possible to reuse most of your web code across both platforms without writing platform-specific code.
With WebViewGold, the barrier to adding advanced native capabilities like Face ID drops to zero. You simply use the provided JavaScript handlers and callbacks as shown above, and your web app becomes a full-featured native app.




