How To Integrate UIWebView to Load URLs Within Your iOS App

Have you ever noticed that whenever we click on a link in Facebook app, it automatically loads the URL within the in-app browser only?

Well, it’s for keeping the users within app only.

And with UIWebView in iOS, iPhone app developers can now integrate this feature in their own mobile apps.

Today, in our iOS app tutorial, we’ll share the implementation process our development team follow with demonstration.

Let’s Get Started

Open your XCode and Create a new project under file menu.


Select Single View Application as the project type and click on next.webview2

Write project name and other details.


Once you create new project, Load a UITableView using following link in ViewController.swift class.

with two options

1) Open Url

2) Open PDF File

Now go to Main.storyboard and drag and drop a new UIViewController from object library.

Search UIWebView object library and drag and drop it into new Controller in storyboard.



Add New file in project WebVC.swift


Set WebVC class to UIViewController with storyboardID.



Set outlet and Delegate of UIWebView.


class WebVC: UIViewController, UIWebViewDelegate {

@IBOutlet weak var web: UIWebView!
var strURL = "" //For get String URL with navigation

When user click on any of option from UITableView, it will navigate to WebVC controller by following code snippet.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let objWeb = self.storyboard?.instantiateViewControllerWithIdentifier("WebVCID") as! WebVC
if indexPath.row == 0 {
objWeb.strURL = //Pass any website URL
} else {
objWeb.strURL = //Pass Any PDF URL
self.navigationController?.pushViewController(objWeb, animated: true)

And in WebVC.swift it will load in UIWebView.

override func viewDidLoad() {

let url = NSURL(string: strURL)
let request = NSURLRequest(URL: url!)

// Do any additional setup after loading the view.

We have integrated UIWebView Delegate for performing action during loading start, end or failure.

//MARK: WebView Delegate Methods
func webViewDidStartLoad(webView: UIWebView) {

func webViewDidFinishLoad(webView: UIWebView) {

func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {

And done!

Here’s the output:ss1


With the above steps, the UIWebView can be implemented in any iOS app. However, if you’re creating an iOS app from ground zero, and have never done it before, then it’s recommended to consult with an expert first, prepare a plan, Hire iPhone app developer to get it developed in the right way.

Grab a free copy of iOS WebView Example from Github.

Author Bio
Hitesh Trivedi
Hitesh Trivedi
Designation: iOS Team Lead

Hitesh Trivedi is an iOS Team Lead at Space-O Technologies. He has over 10 years of experience in iOS app development. He has guided to develop over 100 iPhone apps with unique features and functionalities. He has special expertise in Swift and Objective-C.