How to insert link in button

0

Good,

How do I insert a link into a button I tried as below and did not work.

@IBAction func urlDisplay(_ sender: AnyObject) {

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

    
asked by anonymous 01.10.2016 / 03:30

2 answers

2

In Swift 4 the code looks like this:

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

In your code there is no error, XCode is only notifying you of an update to the function call (shared only)

    
09.05.2018 / 17:54
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)
    }
}
    
03.10.2016 / 04:34