samedi 4 août 2018

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 ::

var newLink = "google.com"
    newLink = link.stringByReplacingOccurrencesOfString("http://", withString: "googlechrome://")
    if UIApplication.shared.canOpenURL(NSURL(string: newLink)! as URL) {
        UIApplication.shared.openURL(NSURL(string: newLink)! 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?




Aucun commentaire:

Enregistrer un commentaire