UserDefaults.standard.value(forKey:“barcodeId”)的问题为!串

时间:2018-02-13 00:04:32

标签: wkwebview uipasteboard

有谁能告诉我为什么用户默认值中复制的数据没有传递正确的值?下面是我的代码,关于所有这些的奇怪部分是在应用程序之外,当粘贴到设备上的笔记或Safari时。它确实超过了正确的数据。注意:我删除了测试网址

   let testURL =  ""

//让barcodeData = UserDefaults.standard.value(forKey:“barcodeId”)为!串

 var barcodeData = UserDefaults.standard.value(forKey: "barcodeId") as! String



override func viewDidLoad() {
    super.viewDidLoad()
}

@IBOutlet weak var webView: WKWebView!

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    webView.navigationDelegate = self
    load(urlString: testURL)
}

// MARK: Private function

func load(urlString string: String) {
    let url = URL(string: string)
    let request = URLRequest(url: url!)
    webView.load(request)
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    webView.evaluateJavaScript("document.getElementById('RCPT_BARCODE').value = \(barcodeData)") {(result, error) in
        guard error == nil else {
            print(error!)
            return
        }
    print(String(describing: result))
    }
}

}

0 个答案:

没有答案