Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Open a url Programmatically

Tags:

url

iphone

I am new to iPhone. I want to open an url in my application. How can I do this task? Please suggest me and provide some useful link.

like image 844
Rupesh Avatar asked Sep 10 '25 02:09

Rupesh


2 Answers

Apparently the link given above is outdated. Here is the update link for the UIApplication class.

The quick and simple code snippet is:

// ObjC
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];

// Swift
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
like image 71
Chris R Avatar answered Sep 12 '25 18:09

Chris R


Update (2016): The best way to do this nowadays is to instantiate and present an SFSafariViewController. This gives the user the security and speed of Safari, and access to any cookies or Safari features they may already have set without having to leave your app.

If you want to open the URL in Safari (and exit your application) you can use the openURL method of UIApplication

If you'd rather have it handled inside of your app, use WKWebView.

like image 29
bpapa Avatar answered Sep 12 '25 17:09

bpapa