【问题标题】:IOS WKWebView Fileupload won't workIOS WKWebView Fileupload 不起作用
【发布时间】:2018-07-21 21:03:32
【问题描述】:

我正在尝试在 WKWebView 中运行 Web 应用程序,在我选择照片库中的图像后,它返回主页并且不上传图像。我收到以下消息:

2018-02-11 14:35:22.870494-0200 Tennis[7144:194670] [MC] 从私人有效用户设置中读取。 2018-02-11 14:35:44.753840-0200 网球 [7144:195114] [发现] 发现扩展时遇到的错误:错误域 = PlugInKit 代码 = 13“查询已取消”用户信息 = {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)
        }
    }
}

我的信息.plist

【问题讨论】:

    标签: ios file-upload swift4 wkwebview


    【解决方案1】:

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

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

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

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

    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
    

    【讨论】:

    • 这很好,我遇到了同样的问题。谢谢!
    【解决方案2】:

    我一直有这个问题,因为我在viewDidAppear 中也有我的webView.load(urlRequest);

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

    原因是因为调用 Library 或 Camera 会打开操作系统对话框来选择或拍照,一旦你这样做了,你的 ViewController 将再次调用 viewWillAppearviewDidAppear 回调,这将重新触发您的初始 webview 加载(刷新页面)。

    【讨论】:

      【解决方案3】:

      正如 marc_ferna 所说,了解从选择图片对话框回调后重新加载 webview 非常重要。因此,如果您将其放在 viewDidLoad 之外的某个地方(例如 viewDidAppear),您的网页会在选择图片对话框后重新加载,并且不会在网络上完成上传。

      【讨论】:

        猜你喜欢
        • 2018-12-23
        • 1970-01-01
        • 1970-01-01
        • 2022-07-07
        • 1970-01-01
        • 1970-01-01
        • 2019-12-25
        • 2018-11-06
        • 1970-01-01
        相关资源
        最近更新 更多