IOS WKWebView Fileupload不起作用

时间:2018-02-11 16:42:38

标签: 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] [发现]发现扩展时遇到的错误:错误域= PlugInKit代码= 13"查询已取消" UserInfo = {NSLocalizedDescription =查询已取消}

我的代码:

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)
        }
    }
}

我的信息列表

enter image description here

3 个答案:

答案 0 :(得分:2)

当我将代码从viewDidAppear移到ViewDidLoad时似乎问题已经消失

   override func viewDidLoad() {

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

我还将目标版本更改为10.3,并在代码中添加了WKWebView,而不是在mainstoryboard中。

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

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 :(得分:0)

我一直遇到这个问题,因为我在SELECT id/2 AS pair_id, avg(value) AS pair_avg FROM (SELECT row_number() OVER (ORDER BY id) + 1 AS id, value FROM tbl) t GROUP BY 1 ORDER BY 1;中也有webView.load(urlRequest);

如前所述,您只需要在viewDidAppear 中添加 webView.load(urlRequest);

原因是因为调用图库或相机会打开OS对话框来拍照或拍照,完成后,ViewController将再次调用viewDidLoadviewWillAppear回调,这将重新触发您的初始Webview负载(刷新页面)。

答案 2 :(得分:0)

正如marc_ferna所说,了解从选择图片对话框中回调后重新加载webview至关重要。因此,如果您将其放置在viewDidLoad中(例如,viewDidAppear)中不存在的位置,则您的网页会在选择图片对话框之后立即重新加载,并且无法完全在网络上上传。