0

I currently made an app that has a UIwebView and a button that invokes the camera. I've managed to successfully get the data to store in UIPastboard. But how do I auto-populate the barcode data on to display on a webbased form? I know I will need to call webViewDidFinishLoading. But I'm not sure how to do this programmatically. The data needs to populate on a certain feild of the form. As a new developer can anyone show me how to accomplish this? Below is my code. This is a for a client and I've changed the URL request for the client's privacy.

import UIKit

class BarcodeViewController: UIViewController {
    @IBOutlet weak var justASecLbl: UILabel!
    @IBOutlet weak var mySearchBar: UISearchBar!
    @IBOutlet weak var myWebView: UIWebView!
    @IBOutlet weak var progressBar: UIProgressView!

    var myTimer = Timer()
    let barcodeData = ""

    @IBAction func back(_ sender: Any)
    {
        if myWebView.canGoBack
        {
            myWebView.goBack()
        }

        // Hide back button
    }

    @IBAction func next(_ sender: Any)
    {
        if myWebView.canGoForward
        {
            myWebView.goForward()
        }
    }

    @IBAction func refresh(_ sender: Any)
    {
        myWebView.reload()
    }

    func searchBarSearchButtonClicked(_ searchBar: UISearchBar)
    {
        mySearchBar.resignFirstResponder()

        if let url = URL(string: mySearchBar.text!)
        {
            myWebView.loadRequest(URLRequest(url: url))
        }
        else
        {
            print ("ERROR")
        }
    }

    func webViewDidStartLoad(_ webView: UIWebView)
    {
        UIApplication.shared.isNetworkActivityIndicatorVisible = true
    }

    func webViewDidFinishLoad(_ webView: UIWebView)
    {
        UIApplication.shared.isNetworkActivityIndicatorVisible = true
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Auto Route first boot to watchStation form website

        myWebView.loadRequest(URLRequest(url: URL(string: "https://www.wufoo.com/gallery/templates/surveys/customer-satisfaction-survey/")!))

    }

    // MARK: - Navigation

    @IBAction func unwindToHomeScreen(segue: UIStoryboardSegue) {
        dismiss(animated: true, completion: nil)
    }

    // TODO: Auto populate barcode Data to web form

    func webViewDidFinishLoad(webView: UIWebView!) {
        UIPasteboard.general.string = barcodeData

        // fill data
        let copiedBarcodeData = barcodeData
        let savedPassword = barcodeData

        let fillForm = String(format: "document.getElementById('expert_email').value = '\(copiedBarcodeData)';document.getElementById('BARCODE*').value = '\(savedPassword)';")
        webView.stringByEvaluatingJavaScript(from: fillForm)

        //check checkboxes
        webView.stringByEvaluatingJavaScript(from: "document.getElementById('BARCODE*').checked = true; document.getElementById('expert_terms_of_service').checked = true;")

        dispatch_after(DispatchTime.now(dispatch_time_t(DISPATCH_TIME_NOW), Int64(1 * NSEC_PER_SEC)), dispatch_get_main_queue()){
            webView.stringByEvaluatingJavaScript(from: "document.forms[\"new_expert\"].submit();")
        }
    }
}
Forge
  • 6,538
  • 6
  • 44
  • 64
Tiktak132
  • 21
  • 6
  • Isn't this a repost of [your previous question](https://stackoverflow.com/questions/48635182/paste-string-data-from-uipastboard)? – rmaddy Feb 08 '18 at 18:50
  • Yes, but no one seems to know or give me any insight on how to structure this – Tiktak132 Feb 08 '18 at 21:05

0 Answers0