How to setup EVURLCache in iOS Swift 3 - ios

I create a app for loading a website. It loads fine but it takes 2 to 3 min every time. So I choose to implement EVURLCache.
I use the pod for EVURLCache. And I import that in MainVC.But I don't know how to setup it.
my Aim is to reduce the load time one time it loaded.
GitHub of EVURLCache : https://github.com/evermeer/EVURLCache
MainVC
import UIKit
import EVURLCache
class MainVC: UIViewController, UIWebViewDelegate {
#IBOutlet weak var webView: UIWebView!
#IBOutlet weak var activityIndicator: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
activityIndicator.startAnimating()
webView.delegate = self
let BASE_URL = "http://www.xeoscript.com/"
let url = URL(string: BASE_URL)
let request = URLRequest(url: url!)
webView.loadRequest(request)
}
func webViewDidFinishLoad(_ webView: UIWebView) {
activityIndicator.stopAnimating()
}
}

As you can see in the appdelegate of the demo, it's enough to add the following line in your didFinishLaunchingWithOptions.
EVURLCache.activate()
See the demo appdelegate for the available configuration options.
If you then run the app, then all your content will be downloaded to a Cache folder in your documents folder. The next time you start the app the files will be loaded from there. It's also possible to include that cache folder inside your app so that people will have the data available directly after downloading your app. The only thin you have to do for this is copying the content from the Cache folder to a PreCache folder in the root of your application.
See the demo app to see how it is setup.

Related

WKWebView is not getting intialized in swift 4 xcode 10

Could anyone help me in understanding why my webView is not getting initialized here. I am getting the following error because webView is nil.
Fatal error: Unexpectedly found nil while unwrapping an Optional value
What exactly I am missing here?
import UIKit
import WebKit
class MemoriesViewController: UIViewController, WKNavigationDelegate {
#IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear( animated )
let urlString:String = "https://www.apple.com"
let url:URL = URL(string: urlString)!
let urlRequest:URLRequest = URLRequest(url: url)
webView.load(urlRequest)
}
}
}
Screenshot for better clarity where the error is actually happening:
Add Webkit.Frameworks to Linked Framework and Libraries
You can then add the Outlet for WKWebView and use your code
import UIKit
import WebKit
class MyWebViewController: UIViewController {
#IBOutlet weak var myWV: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let urlString:String = "https://www.apple.com"
let url:URL = URL(string: urlString)!
let urlRequest:URLRequest = URLRequest(url: url)
myWV.load(urlRequest)
}
}
In Xcode 10, you can foll bellow the step:
Click the project
Go to build phase
Go to Link Binary with Libraries
Click add plus sing under Link Binary with Libraries
open a windows & search Webkit.framework
add & enjoy it
Show bellow image
The problem was my output was not connected to the storyboard. That's why #IBOutlet was not getting initialized.

Enable zooming in WKWebView in Swift 4, Xcode 10, for iOS 12

I am trying to enable zooming/magnification (by pinching) in a very simple WebView in a simple app. (I am pretty new to this).
The Swift code that loads the web page is this and it works fine, I got from here, I think.
import UIKit
import WebKit
class SecondViewController: UIViewController {
#IBOutlet weak var WebViewSchedule: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// load the page
let url = URL(string: "https://mywebsite.com")
let request = URLRequest(url: url!)
WebViewSchedule.load(request)
//how do i make it zoomable ????
}
}
I've looked at a number of answers about this, and they all refer to a property "allowsMagnification". I have tried various ways of using this and got nowhere.
So could some kind person give me a beginners' guide to how to make my iOS Web page zoomable?

How can I specify the user agent of a device in a web app utilizing WKWebView in Swift 4?

I have been trying to figure out how to specify a user agent for my web app in Swift 4 so that the website it opens is in mobile-view. It is defaulting to desktop view instead of mobile. Is there any way to fix this? I am currently learning Swift so I am not that familiar with it yet. I have attached the code below, changing the website for confidentiality reasons.
import UIKit
import WebKit
class ViewController: UIViewController {
var website = "https://www.example.com"
#IBOutlet var webpage: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: website)
let request = URLRequest(url: url!)
webpage.load(request)
}
}
You may change your user agent adding the following HTTPHeaderField:
// valid only for this request
var request = URLRequest(url: URL(string:"https://www.apple.com")!)
request.addValue("myUserAgent", forHTTPHeaderField: "User-Agent")
Another possibility which will completely override the default user agent (might be harmful) is this:
wkWebView.customUserAgent = "myUserAgent"

Swift Error : Classes implemented in two places but files I don't touch?

I am testing out swifts UIWebView, I have placed a simple UIWebview on my storyboard and this is my viewController code
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = URL(string: "https://mywebsitehere.com")
webView.loadRequest(URLRequest(url: url!))
} }
Unfortunately I am getting this Error below, I have added App transport security settings to my app like other answers to a similar question have said to do but it still isn't working...
Can anyone help?
objc[946]: Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x124feecc0) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x124e056f0). One of the two will be used. Which one is undefined.
This is bug with xCode while simulating the real iOS device, some time it through such kind of error.
Please check whether your url is active or not.
let url = URL(string: "https://google.com")
webView.loadRequest(URLRequest(url: url!))
I used the same code with google URL and it is working.

Integrate web text into App (Swift)

I am having a news section in the App and i want to renew it through a website that shows the text and pictures it should copy how do i do that?
I just want that it exactly copies the text and pictures from a website.
Thanks in advance.
You can use UIWebView for that! First, drop a web view on the scene and then:
Here is the code for SWIFT 2:
import UIKit
class ViewController: UIViewController{
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad(){
super.viewDidLoad()
let url = NSURL(string: "http://www.google.com") // instead of "http://www.google.com", you put the website link you want, but with "http://" or "https://"
let urlRequest = NSURLRequest(URL: url!)
webView.loadRequest(urlRequest)
}
}
Version For SWIFT 3:
import UIKit
class ViewController: UIViewController, UIWebViewDelegate{
#IBOutlet var webView: UIWebView!
override func viewDidLoad(){
super.viewDidLoad()
let url = URL(string: "http://www.booking.com") // instead of "http://www.google.com", you put the website link you want, but with "http://" or "https://"
let urlRequest = URLRequest(url: url!)
webView.loadRequest(urlRequest)
}
}
So at the end you need to implement rss reader if your website supports.
https://www.raywenderlich.com/2636/rss-reader-tutorial-for-ios-how-to-make-a-simple-rss-reader-iphone-app
If website does not support then you could implement below ways.
Open that URL in UIWebView or Copy though each text and image on your server and make API to display on app.

Resources