【问题标题】:how to open google chrome in swift如何快速打开谷歌浏览器
【发布时间】:2018-08-04 10:10:03
【问题描述】:

我对 swift 几乎是新手。每当用户按下特定按钮时,我都想打开谷歌浏览器。 我找到了这个::

let chromeURL = "googlechrome:\(presenter.createOrderApp(data: data, aptId: aptID))"
    //UIApplication.shared.openURL(URL(string: chromeURL)!)
    if UIApplication.shared.canOpenURL(NSURL(string: chromeURL)! as URL) {
        UIApplication.shared.openURL(NSURL(string: chromeURL)! as URL)
    } else {
        let alertController = UIAlertController(title: "Sorry", message: "Google Chrome app is not installed", preferredStyle: .alert)
        let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alertController.addAction(okAction)
        self.present(alertController, animated: true, completion: nil)
    }

但我收到错误消息:

无法将“()”类型的值转换为预期的参数类型“字符串”

'(UnsafePointer!, UnsafePointer!) -> Int32' 类型的值没有成员 'stringByReplacingOccurrencesOfString' 有人知道这里出了什么问题吗?

更新:

 func createOrderApp(data: [String:Any] , aptId : String) {
        ApiGenerator.request(targetApi: OrderService.createOrderApp( data:data ,   aptId: aptId), responseModel: CreatePaymentOrderAppByUser.self, success: { (response) in
            print("success")
            if response.response.statusCode == 200 {
                self.view?.createOrderAppSuccess(data: response.body!)
            }else {
                do{
                    var errorMessage = try response.response.mapString()
                    errorMessage = errorMessage.replacingOccurrences(of: "\"", with: "",
                                                                     options: NSString.CompareOptions.literal, range:nil)
                    print("errorMessage =============")
                    print(errorMessage)
                    self.view?.createOrderAppFailed(errorMessage: errorMessage)

                }catch let error{
                    print(error)
                    self.view?.createOrderAppFailed(errorMessage: " Error")
                }
            }
        }) { (error) in
            print(error)
            self.view?.createOrderAppFailed(errorMessage: " Error")
        }
    }

/////////// 我刚刚找到了一种打开谷歌浏览器的方法,但它显示我的地址为空

【问题讨论】:

  • @Kamran 如您所见,我在这里添加了相同的代码,这对我不起作用!这就是我添加问题的原因
  • 原因是UrlString 错误。您无法提供有效的 url,这就是它失败的原因。传递一个有效的 url 并检查。
  • 你是什么意思?我的网址适用于 safari,但我要在 chrome 中打开它

标签: iphone swift google-chrome web safari


【解决方案1】:
let chromeURL = "googlechrome://"
UIApplication.shared.openURL(URL(string: chromeURL)!)

let chromeURL = "googlechrome://http://api.sharjbook.com/api/Order/CreatePaymentOrder"
UIApplication.shared.openURL(URL(string: chromeURL)!)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多