Introduction
Creating a web view mobile application is a basic and simple task for any developer who is doing it. The major motive of creating a web view the mobile application is because we already have a website with a perfect mobile view, but we need an application that helps us to view only the particular website, instead of a browser. This kind of application acts and works like a browser, but it displays only the particular website. In this article we will discuss creating a web view application for the IOS, using a swift programming language.
Xcode
For creating this application, I am going to use the Xcode IDE by Apple. Xcode helps you in different ways while creating an application. The basic and very important thing is it has a default simulator that helps you to simulate the app which you developed, without the help of any other software or any other device. By using that simulator, you can make a simulation of your application for many numbers of devices, which supports the operating system you have chosen. You can download the Xcode from apple’s app store which is available for free of cost. Apart from Xcode, you can also use different types of IDE’s which support swift programming language, but while doing like that the steps and execution procedure may vary, but there will be no changes in the code.
Creating an application
First, you need to open the Xcode IDE. In the appearing screen, you need to select Create a new Xcode project.
On the next screen under the iOS tab select the app option and click next.
In the next screen you need to enter the name of the app you are developing and the team you are working with, then click Next.
Then you need to select the location where you are going to store the project then click create.
You can choose the version of iOS by clicking the drop-down box which is available under deployment info. Then you can type your code in ViewController.swift by clicking it.
First we are going to import the UI kit and Web kit for the purpose of using the system UI and web configuration.
- import UIKit
- import WebKit
- import UIKit
- import WebKit
- class ViewController: UIViewController, WKUIDelegate {
- var webView: WKWebView!override func loadView() {
- let webConfiguration = WKWebViewConfiguration()
- webView = WKWebView(frame: .zero, configuration: webConfiguration)
- webView.uiDelegate = self
- view = webView
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- let myURL = URL(string: "https://www.c-sharpcorner.com")
- let myRequest = URLRequest(url: myURL!)
- webView.load(myRequest)
- }
- }
After coding your project now, we are going to test the project. For that, we are going to use the default simulator. You can choose the device which you are going to simulate by clicking the drop-down box nearby the project name. Then you click the build button to start building the project.
Then the simulator opens automatically. Here I chose iPhone 11 and the screen of iPhone 11 is opening now. It displays the web content in the mobile application.
You can also analyze the performance of the application by the given option in the Xcode. It displays the details of how much CPU the app is using and the memory used by the app and also the network used by the app. This gives you a clear idea of how your app is working.
There are a lot more options available in Xcode which I will explain in my upcoming articles.
Conclusion
This is one of the simplest ways of creating a mobile application. This may help some people to create their applications for their website. You may also create a web view app with customized buttons. I will explain those things in my upcoming articles. Thank You!