3
votes

I'm trying to run a web application inside WKWebView and after I select the image in Photo Library, it returns to home page and doesn't upload the image. I got the message below:

2018-02-11 14:35:22.870494-0200 Tennis[7144:194670] [MC] Reading from private effective user settings. 2018-02-11 14:35:44.753840-0200 Tennis[7144:195114] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

My Code:

import UIKit
import WebKit
class ViewController: UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate {

    @IBOutlet weak var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(_ animated: Bool) {

        let url:URL = URL(string: "http://serivinho:8001/")!
        let urlRequest: URLRequest = URLRequest(url: url)
        webView.load(urlRequest);
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func dismiss(animated flag: Bool, completion: (() -> Void)?)
    {
        if self.presentedViewController != nil {
            super.dismiss(animated: flag, completion: completion)
        }
    }
}

My Info.plist

enter image description here

3

3 Answers

2
votes

It seems that the problem gone when I moved the code from viewDidAppear to ViewDidLoad

   override func viewDidLoad() {

        let url:URL = URL(string: "http://serivinho:8001/")!
        let urlRequest: URLRequest = URLRequest(url: url)
        webView.load(urlRequest);
    }

I also changed the target version to 10.3 and added the WKWebView in the code and not in the mainstoryboard.

I still receive some log messages but they didn't prevent from working:

18-02-11 20:25:01.535257-0200 Tennis[406:75090] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-11 20:25:01.537713-0200 Tennis[406:75090] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-11 20:25:10.228575-0200 Tennis[406:75090] [Generic] Creating an image format with an unknown type is an error
2018-02-11 20:25:52.676053-0200 Tennis[406:75090] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-11 20:25:52.676252-0200 Tennis[406:75090] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-11 20:25:58.340272-0200 Tennis[406:75090] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-11 20:25:58.340458-0200 Tennis[406:75090] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
1
votes

I've been having this problem because I also had my webView.load(urlRequest); in viewDidAppear.

As you mentioned, you need to add the webView.load(urlRequest); only in viewDidLoad.

The reason is because calling the Library or Camera will open up the OS dialog to pick or take a photo, and once you are done doing that, your ViewController will call again the viewWillAppear and viewDidAppear callbacks and that will re-trigger your initial webview load (refreshing the page).

0
votes

As marc_ferna said, it's very important to understand that webview reloaded after callback from select picture dialog. So if you put it somewhere not in viewDidLoad (viewDidAppear for example) your webpage reloaded just after select picture dialog and not complete upload on the web.