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)
}
but I get error which says:
Cannot convert value of type '()' to expected argument type 'String'
Value of type '(UnsafePointer!, UnsafePointer!) -> Int32' has no member 'stringByReplacingOccurrencesOfString' does anybody has any idea what is wrong here?
UPDATED:
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)!)