Skip to content

A simple project to test out Microblink's BlinkID SDK through SwiftUI and WebView

Notifications You must be signed in to change notification settings

mparadina/microblink-ios-webview-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Microblink iOS WebView Test

Intro

This repo shows a basic POC for running Microblink's BlinkID using SwiftUI and WebView

  • The application only consists of one view (WebView)
  • Loads the web demo site https://blinkid-test.netlify.app/ into the browser
  • Asks for camera permission when entering the scanning process and is making sure that scanning and extraction work

Requirements

In order for the WebView to work, there are a few items that need to be addressed first.

  1. Add the NSCameraUsageDescription to your Info.plist file. This is important as the camera scanning will not work if the end-user declines the alert pop-up.

  2. Add the additional permissions when setting up WebView:

webViewConfiguration.userContentController.add(context.coordinator, name: "mediaCapture")

webViewConfiguration.allowsInlineMediaPlayback = true
webViewConfiguration.allowsPictureInPictureMediaPlayback = true
webViewConfiguration.allowsAirPlayForMediaPlayback = true
                
let webView = WKWebView(frame: .zero, configuration: webViewConfiguration)
  1. Display the camera permission alert when the custom mediaCapture handler is triggered:
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
    if message.name == "mediaCapture" {
        requestCameraPermission()
    }
}
        
private func requestCameraPermission() {
    AVCaptureDevice.requestAccess(for: .video) { granted in
        if granted {
            print("Camera access granted.")
        } else {
            print("Camera access denied.")
        }
    }
}

Conclusion

Hope this helps, and if you'll have any additional questions, please reach out to us and we'll be happy to help.

About

A simple project to test out Microblink's BlinkID SDK through SwiftUI and WebView

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages