IOS WKWebView文件上载无法工作

IOS WKWebView文件上载无法工作,ios,file-upload,swift4,wkwebview,Ios,File Upload,Swift4,Wkwebview,我试图在WKWebView中运行一个web应用程序,在我选择照片库中的图像后,它会返回主页,而不会上载图像。我得到的信息如下: 2018-02-11 14:35:22.870494-0200网球[7144:194670][MC]阅读私人有效用户设置。 2018-02-11 14:35:44.753840-0200网球[7144:195114][discovery]发现扩展时遇到错误:Error Domain=PlugInKit Code=13 query cancelled UserInfo={

我试图在WKWebView中运行一个web应用程序,在我选择照片库中的图像后,它会返回主页,而不会上载图像。我得到的信息如下:

2018-02-11 14:35:22.870494-0200网球[7144:194670][MC]阅读私人有效用户设置。 2018-02-11 14:35:44.753840-0200网球[7144:195114][discovery]发现扩展时遇到错误:Error Domain=PlugInKit Code=13 query cancelled UserInfo={NSLocalizedDescription=query cancelled}

我的代码:

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)
        }
    }
}
我的信息列表


当我将代码从viewdidebeen移动到viewdideload时,问题似乎消失了

   override func viewDidLoad() {

        let url:URL = URL(string: "http://serivinho:8001/")!
        let urlRequest: URLRequest = URLRequest(url: url)
        webView.load(urlRequest);
    }
我还将目标版本更改为10.3,并在代码中添加了WKWebView,而不是在MainstryBoard中

我仍然收到一些日志消息,但它们没有阻止工作:

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

我一直有这个问题,因为我也有我的webView.loadurlRequest;在视图中出现

正如您所提到的,您需要添加webView.loadurlRequest;仅在viewDidLoad中


原因是,调用库或相机将打开操作系统对话框以拾取或拍摄照片,一旦完成此操作,ViewController将再次调用ViewWillDisplay和ViewDidDisplay回调,这将重新触发初始webview加载刷新页面。

正如marc_ferna所说,了解webview在从“选择图片”对话框回调后重新加载是非常重要的。因此,如果你把它放在某个不在ViewDiLoad ViewDiDisplay中的地方,例如,你的网页在“选择图片”对话框之后重新加载,但没有在web上完成上载。

这很好,我也遇到了同样的问题。非常感谢。