0

I am trying to build a simple Application for IOS, which is showing me a Webpage which functions as a QRCode Scanner. When i am visiting the webpage "qrcodescan.in" with safari on my phone, it accesses my iPhone Camera without any problems.

enter image description here

And this is how it looks when i Run the Application on my phone. enter image description here

So as an application i can't access my phone camera, but on the website via Safari it is accessible.

The following is my Code in Xcode.


import UIKit
import WebKit
class ViewController: UIViewController,WKUIDelegate {

    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }



    override func viewDidLoad() {
        super.viewDidLoad()

        let myURL = URL(string:"https://qrcodescan.in")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)



    }


}

Also I added all Keys into "info.plist" for accessing the Camera function on the Phone.

<key>NSCameraUsageDescription</key>
<string>${PRODUCT_NAME} Camera Usage</string>

<key>NSPhotoLibraryAddUsageDescription</key>
<string>${PRODUCT_NAME} library Usage</string>

So i searched a lot on the web to find anything helpful and wasn't successful. I hope somebody can help me.

Also to mention. I am absolute newbie when it comes to Swift or IOS App development in General.

Thanks in advance.

2 Answers2

0

WKWebView and the web view in the native Safari don't offer the same APIs (see here). That is the main reason your code doesn't work.

See this SO answer on how to access the camera on a WKWebView.

blop
  • 103
  • 9
-1

I think the problem is with Webview not from your app side, ask your backend developer to make Webview compatible for iOS application.

Ankur Purwar
  • 275
  • 2
  • 9