如何快速打开谷歌浏览器 [英] how to open google chrome in swift
本文介绍了如何快速打开谷歌浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我几乎是新手.我想在用户按下特定按钮时打开谷歌浏览器. 我发现了这个::
i'm almost new to swift . i want to open google chrome whenever user press an specific button. I found this ::
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)
}
但出现错误提示:
无法将类型'()'的值转换为预期的参数类型'字符串'
Cannot convert value of type '()' to expected argument type 'String'
类型'((UnsafePointer !, UnsafePointer!)-> Int32'的值没有成员'stringByReplacingOccurrencesOfString' 有人知道这是怎么回事吗?
Value of type '(UnsafePointer!, UnsafePointer!) -> Int32' has no member 'stringByReplacingOccurrencesOfString' does anybody has any idea what is wrong here?
已更新:
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")
}
}
//////////// 我刚刚找到了一种打开谷歌浏览器的方法,但是它显示了我的地址为空
/////////// I just found a way to open google chrome but it shows my address empty
推荐答案
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)!)
这篇关于如何快速打开谷歌浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文