Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 204
theDC Avatar asked Jan 18 '15 14:01

theDC


People also ask

How to fix ‘open web pages in the app’ function not working?

Go to your settings, then go to chrome, then tap on the the dots (the more options button), then click on “uninstall updates”, then try again. 12:38 pm (IST): One of the affected users suggested a workaround that will possibly resolve the ‘Open web pages in the app’ function not working issue.

How to redirect a page to another page in react?

The usual practice with redirecting to another page on React is to use the react-router-dom package; then, we apply the Route exact path and the Link function to complete the coding process. The processes are mostly similar to the explanation above when we attempt to use the onClick event listener with the react-router-dom package.

How do I render a button in react?

You can render a normal html <button> with React, as usual React prop conventions apply, such as onClick, style, etc. The button's onClick prop is what allows us to add a function which fires when the user clicks on the button.

How to make a modern looking react button?

For example, the html button's text is already centered for us. We mainly want to change the background color, increase the font size, add more padding (vertical then horizontal below), add a border radius, and change the cursor to a pointer. Doing those 5 things will give you a modern looking React Button you can use:


2 Answers

missing url scheme

UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil) 
like image 197
oiledCode Avatar answered Sep 22 '22 20:09

oiledCode


Swift 4, safely unwrapped optional, check if canOpenURL

if let url = URL(string: "https://www.google.com"),         UIApplication.shared.canOpenURL(url) {             UIApplication.shared.open(url, options: [:]) } 
like image 44
Aaron Halvorsen Avatar answered Sep 22 '22 20:09

Aaron Halvorsen