Load a URL inside the app
1. Search for, drag and drop WKWebView into the app.
2. Constrain it.
3. Create an outlet.
4. Make sure the outlet is strong and not weak.
Go to Info.plist and add a key:
NSAppTransportSecurity
It will be set to dictionary.
Click on the triangle button till it faces downwards and click on the + sign.
Select Allows Arbitrary Loads and Allows Arbitrary Loads Web Content
Change both boolean values to YES
In the source code, import WebKit
Add the following code to ViewDidLoad:
let firstURL = URL(string: "http://www.youtube.com")
let requestObj = URLRequest(url: firstURL!)
myWebViewOne.load(requestObj)
2. Constrain it.
3. Create an outlet.
4. Make sure the outlet is strong and not weak.
Go to Info.plist and add a key:
NSAppTransportSecurity
It will be set to dictionary.
Click on the triangle button till it faces downwards and click on the + sign.
Select Allows Arbitrary Loads and Allows Arbitrary Loads Web Content
Change both boolean values to YES
In the source code, import WebKit
Add the following code to ViewDidLoad:
let firstURL = URL(string: "http://www.youtube.com")
let requestObj = URLRequest(url: firstURL!)
myWebViewOne.load(requestObj)
You must check to make sure the URL entered has the prefix http
If you need the URL to stop playing a video:
myWebViewOne.reload()
If you need it to stop loading:
myWebViewOne.stopLoading()
If you need the URL to stop playing a video:
myWebViewOne.reload()
If you need it to stop loading:
myWebViewOne.stopLoading()
Comments
Post a Comment