How to insert link on button

Asked

Viewed 333 times

0

Good,

how do I insert a link in a tried button below and it didn’t work.

@IBAction func urlDisplay(_ sender: AnyObject) {

    UIApplication.sharedApplication().openURL(NSURL(String:"http://www.quatenus.co.ao")!)
}

Print

2 answers

2


On Swift 4 the code would look like this:

UIApplication.shared.openURL(URL(string: "http://www.quatenus.co.ao")!)

In your code is not with error, the Xcode is only warning that there was an update in the function call (only Shared)

2

Using Swift 3 the code would look like this:

@IBAction func urlDisplay(_ sender: AnyObject) {
    let url = URL(string: "http://www.quatenus.co.ao/")!
    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.openURL(url)
    }
}
  • Ops. o Xcode da erro de: 'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: Instead

  • This message is a Warning and not an error. I compiled the code in iOS 10 and it worked normally. You can make the change that Xcode is suggesting without any problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.