Web View Implementation
Best practices to follow when using the application withn a webview in your native mobile application.
Android
Configuration
Step 1: Grant Basic Application Level Permissions
The app that contains the WebView must first declare and obtain the following permissions:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA" />
Step 2: Override the "webChromeClient" property
Override the following methods within 'webChromeClient' property of your WebView, using either an inline object or a custom class.
This function is used to grant the relevant permissions to the webpage:
override fun onPermissionRequest(request: PermissionRequest) {
request.grant(request.resources)
}
Set the following WebView properties:
wvSettings.javaScriptEnabled = true
wvSettings.domStorageEnabled = true
wvSettings.allowFileAccess = true
wvSettings.allowContentAccess = true
wvSettings.javaScriptCanOpenWindowsAutomatically = true
wvSettings.mediaPlaybackRequiresUserGesture = false
iOS
Configuration
Step 1: Declare the camera permission
Declare a camera permission message by adding NSCameraUsageDescription to the info.plist.
Step 2: WebView definition
//Create Web View
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
WKWebView(frame: CGRect(x: 0, y: 0, width: 200, height: 200), configuration: webConfiguration)
//Load Web View
let request = URLRequest(url: "yourWebUrl")
webView.load(request)
Updated 3 months ago