DCDC DCDC - 1 year ago 113
iOS Question

Swift - open web page in app, button doesn't react

I created a button to make a call from app:

@IBAction func callButton(sender: AnyObject) {
if (PhoneNumber != ""){
UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(PhoneNumber)")!)

and it works perfectly fine. Strange thing happens when I want to open a web page. I use nearly exactly same code

@IBAction func openWeb(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string: "www.google.com")!)

But this time button doesn't react and nothing happens. Wherever I was looking for some information about opening web pages in safari from the app, the code was written exactly this way. Do you have any idea where the problem is?

Thanks in advance!

Answer Source

missing url scheme

UIApplication.sharedApplication().openURL(NSURL(string: "http://www.google.com")!)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download