mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-26 13:29:31 -04:00
web view delegate with response cache
This commit is contained in:
parent
73774c57a6
commit
962f5b8f3e
@ -30,11 +30,15 @@ class MainController: UIViewController {
|
||||
private(set) var tableOfContentsController: TableOfContentsController?
|
||||
let searchBar = SearchBar()
|
||||
|
||||
private(set) var article: Article? {
|
||||
var article: Article? {
|
||||
willSet(newArticle) {
|
||||
article?.removeObserver(self, forKeyPath: "isBookmarked")
|
||||
newArticle?.addObserver(self, forKeyPath: "isBookmarked", options: .New, context: context)
|
||||
}
|
||||
didSet {
|
||||
// searchbar title
|
||||
// bookmarked or not
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Override
|
||||
|
@ -23,15 +23,20 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate,
|
||||
}
|
||||
|
||||
func webViewDidStartLoad(webView: UIWebView) {
|
||||
|
||||
URLResponseCache.shared.start()
|
||||
}
|
||||
|
||||
func webViewDidFinishLoad(webView: UIWebView) {
|
||||
URLResponseCache.shared.stop()
|
||||
|
||||
}
|
||||
|
||||
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
|
||||
// handle error
|
||||
print(error)
|
||||
|
||||
article = nil
|
||||
URLResponseCache.shared.stop()
|
||||
}
|
||||
|
||||
// MARK: - SFSafariViewControllerDelegate
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.133</string>
|
||||
<string>1.8.140</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.135</string>
|
||||
<string>1.8.142</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -1,33 +0,0 @@
|
||||
//
|
||||
// PacketAnalyzer.swift
|
||||
// Kiwix
|
||||
//
|
||||
// Created by Chris Li on 7/18/16.
|
||||
// Copyright © 2016 Chris. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class PacketAnalyzer {
|
||||
static let sharedInstance = PacketAnalyzer()
|
||||
private var listening = false
|
||||
private var images = [(data: NSData, url: NSURL)]()
|
||||
|
||||
func startListening() {
|
||||
listening = true
|
||||
}
|
||||
|
||||
func stopListening() {
|
||||
listening = false
|
||||
images.removeAll()
|
||||
}
|
||||
|
||||
func addImage(data: NSData, url: NSURL) {
|
||||
guard listening else {return}
|
||||
images.append((data, url))
|
||||
}
|
||||
|
||||
func chooseImage() -> (data: NSData, url: NSURL)? {
|
||||
return images.first
|
||||
}
|
||||
}
|
@ -15,14 +15,19 @@ class URLResponseCache {
|
||||
|
||||
func start() {
|
||||
listening = true
|
||||
clear()
|
||||
}
|
||||
|
||||
func stop() {
|
||||
listening = false
|
||||
}
|
||||
|
||||
func clear() {
|
||||
responses.removeAll()
|
||||
}
|
||||
|
||||
func cache(response response: NSURLResponse) {
|
||||
guard listening else {return}
|
||||
guard let url = response.URL else {return}
|
||||
responses[url] = response
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user