How to create a WebView in iOS/iPhone?

To create a web view in iOS we'll use Webkit framework of iOS. Previously UIWebView was used to create web views but that has been deprecated now.

We'll use WebKit View in this project.

  • Create a new project and from object library drag and drop webKit View to the ViewController.

  • Give constraints as per your requirement.

  • Make an outlet connection to the webKit in ViewController.

  • We'll open facebook in this example using the code below.

let url = URL(string: "")
override func viewDidLoad() {
   let request = URLRequest.init(url: self.url!)

Now finally we need to add a key App Transport Security Settings in info.plist.

Open your info.plist file as source code and paste the following code −

<!--Include to allow all connections (DANGER)-->

Note − In devices running iOS 10.0 or later we also need to add Photo library usage description and Camera usage description in the info.plist


This is how the app looks when running on a simulator.

Updated on: 30-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started