【问题标题】:'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead in Swift 3 [duplicate]iOS 10.0 中不推荐使用“openURL”:请使用 openURL:options:completionHandler: 而不是 Swift 3 [重复]
【发布时间】:2017-07-12 09:26:58
【问题描述】:

我在Swift3 中使用了打开的 webLink url 代码,但是当我使用它时会给我这个警告;

'openURL' 在 iOS 10.0 中已弃用:请改用 openURL:options:completionHandler:

我该如何解决它,我的代码在下面。

let myUrl = "http://www.google.com"
 if !myUrl.isEmpty {
                                UIApplication.shared.openURL(URL(string: "\(myUrl)")!)
                            }

谢谢。

【问题讨论】:

    标签: ios uiwebview swift3


    【解决方案1】:

    使用喜欢

     //inside scope use this
     let myUrl = "http://www.google.com"
        if let url = URL(string: "\(myUrl)"), !url.absoluteString.isEmpty {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    
        // or outside scope use this
        guard let url = URL(string: "\(myUrl)"), !url.absoluteString.isEmpty else {
           return
        }
         UIApplication.shared.open(url, options: [:], completionHandler: nil)
    

    如需更多参考,请参阅此示例link

    【讨论】:

    • 老兄工作了,我会批准你的回答。
    • 杰出........
    【解决方案2】:

    尝试使用这个:

    UIApplication.shared.open(URL(string: "\(myUrl)")!)
    

    【讨论】:

    • 你读过这个问题吗?
    • 这是一个正确、简洁的答案。接受的答案只是添加了一堆不相关的示例代码。
    • 更简单更干净?
    • @ArielAntonioFundora 你看答案了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 2019-02-28
    相关资源
    最近更新 更多