mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-28 06:25:04 -04:00
article object when book loading finishes
This commit is contained in:
parent
962f5b8f3e
commit
495de1f08d
@ -32,6 +32,10 @@ class JSInjection {
|
||||
webView.stringByEvaluatingJavaScriptFromString(jString)
|
||||
}
|
||||
|
||||
class func getTitle(from webView: UIWebView) -> String? {
|
||||
return webView.stringByEvaluatingJavaScriptFromString("document.title")
|
||||
}
|
||||
|
||||
class func getTableOfContents(webView: UIWebView) -> [HTMLHeading] {
|
||||
guard let context = webView.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as? JSContext,
|
||||
let path = NSBundle.mainBundle().pathForResource("getTableOfContents", ofType: "js"),
|
||||
|
@ -36,8 +36,8 @@ class MainController: UIViewController {
|
||||
newArticle?.addObserver(self, forKeyPath: "isBookmarked", options: .New, context: context)
|
||||
}
|
||||
didSet {
|
||||
// searchbar title
|
||||
// bookmarked or not
|
||||
configureSearchBarPlaceHolder()
|
||||
configureBookmarkButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import CoreData
|
||||
import SafariServices
|
||||
import JavaScriptCore
|
||||
import DZNEmptyDataSet
|
||||
@ -29,6 +30,11 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate,
|
||||
func webViewDidFinishLoad(webView: UIWebView) {
|
||||
URLResponseCache.shared.stop()
|
||||
|
||||
guard let url = webView.request?.URL,
|
||||
let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return}
|
||||
article.title = JSInjection.getTitle(from: webView)
|
||||
article.thumbImageURL = URLResponseCache.shared.firstImage()?.absoluteString
|
||||
self.article = article
|
||||
}
|
||||
|
||||
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.140</string>
|
||||
<string>1.8.156</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.142</string>
|
||||
<string>1.8.158</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -12,15 +12,17 @@ import CoreData
|
||||
|
||||
class Article: NSManagedObject {
|
||||
|
||||
class func addOrUpdate(title: String? = nil, url: NSURL, book: Book, context: NSManagedObjectContext) -> Article? {
|
||||
class func addOrUpdate(url url: NSURL, context: NSManagedObjectContext) -> Article? {
|
||||
guard let bookID = url.host,
|
||||
let book = Book.fetch(bookID, context: context),
|
||||
let url = url.absoluteString else {return nil}
|
||||
|
||||
let fetchRequest = NSFetchRequest(entityName: "Article")
|
||||
fetchRequest.predicate = NSPredicate(format: "url = %@", url.absoluteString!)
|
||||
fetchRequest.predicate = NSPredicate(format: "url = %@", url)
|
||||
|
||||
let article = Article.fetch(fetchRequest, type: Article.self, context: context)?.first ?? insert(Article.self, context: context)
|
||||
|
||||
article?.title = title
|
||||
article?.url = url.absoluteString!
|
||||
article?.url = url
|
||||
article?.book = book
|
||||
|
||||
return article
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user