【问题标题】:How to send a string to url?如何将字符串发送到 url?
【发布时间】:2019-04-18 09:38:47
【问题描述】:

我正在设置一个条形码阅读器应用程序,有 3 个标签栏项目,其中一个是“扫描”标签,另一个是“WEBVIEW”标签。当用户扫描条形码或二维码时,它会给出一个字符串并转到 webview 的 url。我想将此字符串发送到 url 并打开 webview 选项卡。你能帮我解决这个问题吗?

  if (metadataObjects.count > 0 && metadataObjects.first is AVMetadataMachineReadableCodeObject) {

        let scan = metadataObjects.first as! AVMetadataMachineReadableCodeObject

        let alertController = UIAlertController(title: "Barkod Tarandı", message: scan.stringValue, preferredStyle: .alert)



        alertController.addAction(UIAlertAction(title: "TAMAM", style: .default, handler:nil))



        present(alertController, animated: true, completion: nil)



        if(scan.stringValue != nil)
        {
            if let aString = URL(string: "" + ("http://www.truebilisim.com/myiphone/true/mymagazaplus/barkod.php?barkod=\(scan.stringValue)")) {
                webalani.loadRequest(URLRequest(url: aString))
            }
        }

    }

【问题讨论】:

  • 什么是问题?
  • 它不工作。
  • 什么不起作用?没有人能读懂你的心思。请添加您期望的信息以及会发生什么。
  • 当我点击“TAMAM”按钮时,它给了我一条警告信息,但没有转到带有字符串的 webview 选项卡。字符串去但 webview 不加载或字符串不去并且 webview 也不加载?我不明白。
  • 如果您想在点击操作按钮时打开 URL,您必须将代码放入操作的 handler 参数中,即nil。

标签: swift xcode


【解决方案1】:

使用它必须工作的 NSURL。

webalani.loadRequest(NSURLRequest(URL: NSURL(string: "aString")!))

并确保你的这一行也必须是 NSURL

if let aString = URL(string: "" + ("http://www.truebilisim.com/myiphone/true/mymagazaplus/barkod.php?barkod=\(scan.stringValue)")) {

【讨论】:

    猜你喜欢
    • 2018-07-25
    • 1970-01-01
    • 2020-08-05
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多