
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Open Website in iOS Web Browser from Application
In this post we will learn how to open website in iOS browser.
We will open Facebook in iOS browser.
Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “OpenBrowser”
Step 2 − Open Main.storyboard and add a button as shown below. I have given the button title as “Open Facebook”
Step 3 − Attach one @IBAction function in ViewController, name it openBrowser
Step 4 − In openBrowserFunction write the code to open URL like shown below
@IBAction func openBrowsere(_ sender: Any) { let url = URL(string: "https://www.facebook.com")! if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } }
In the above code as you can see we are using canOpenURL and openURL APIs.
canOpenURL checks whether the given URL can be opened by the app. Then openURL actually opens the given URL with appropriate app.
Step 5 − Run the app. Click on open Facebook button. You should see the browser opening the Facebook page.