如何快速打开谷歌浏览器

时间:2018-08-04 10:10:03

标签: iphone swift google-chrome web safari

我几乎是新手。我想在用户按下特定按钮时打开谷歌浏览器。 我发现了这个::

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")
        }
    }

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

1 个答案:

答案 0 :(得分: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)!)