mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 22:10:57 -04:00
commit
This commit is contained in:
parent
ed71819e64
commit
2f2157d458
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB |
@ -9,6 +9,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import SafariServices
|
import SafariServices
|
||||||
import CoreSpotlight
|
import CoreSpotlight
|
||||||
|
import CloudKit
|
||||||
|
|
||||||
// MARK: - Web
|
// MARK: - Web
|
||||||
|
|
||||||
@ -177,7 +178,14 @@ extension MainController: ButtonDelegates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func syncBookmark(article: Article) {
|
func syncBookmark(article: Article) {
|
||||||
|
guard let record = article.cloudKitRecord else {return}
|
||||||
|
// guard let book = article.book else {return}
|
||||||
|
// let record = book.cloudKitRecord
|
||||||
|
let container = CKContainer(identifier: "iCloud.org.kiwix")
|
||||||
|
let database = container.privateCloudDatabase
|
||||||
|
database.save(record, completionHandler: {record, error in
|
||||||
|
print(error?.localizedDescription)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let url = webView.request?.url,
|
guard let url = webView.request?.url,
|
||||||
@ -189,6 +197,7 @@ extension MainController: ButtonDelegates {
|
|||||||
buttons.bookmark.isHighlighted = article.isBookmarked
|
buttons.bookmark.isHighlighted = article.isBookmarked
|
||||||
|
|
||||||
indexBookmark(article: article)
|
indexBookmark(article: article)
|
||||||
|
let op = Art
|
||||||
syncBookmark(article: article)
|
syncBookmark(article: article)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.3483</string>
|
<string>1.8.3509</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.3483</string>
|
<string>1.8.3509</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
9734E54E1D289D060061C39B /* Welcome.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9734E54D1D289D060061C39B /* Welcome.storyboard */; };
|
9734E54E1D289D060061C39B /* Welcome.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9734E54D1D289D060061C39B /* Welcome.storyboard */; };
|
||||||
973A5C921DEA3F5600C7804C /* CoreDataTableBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973A5C911DEA3F5600C7804C /* CoreDataTableBaseController.swift */; };
|
973A5C921DEA3F5600C7804C /* CoreDataTableBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973A5C911DEA3F5600C7804C /* CoreDataTableBaseController.swift */; };
|
||||||
973A5C951DEA6DD000C7804C /* URLResponseCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973A5C931DEA6CA900C7804C /* URLResponseCache.swift */; };
|
973A5C951DEA6DD000C7804C /* URLResponseCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973A5C931DEA6CA900C7804C /* URLResponseCache.swift */; };
|
||||||
|
973A5C991DEBC54800C7804C /* CloudKitOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973A5C981DEBC54800C7804C /* CloudKitOperations.swift */; };
|
||||||
973BCD1A1CEB402900F10B44 /* KiwixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD181CEB402900F10B44 /* KiwixTests.swift */; };
|
973BCD1A1CEB402900F10B44 /* KiwixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD181CEB402900F10B44 /* KiwixTests.swift */; };
|
||||||
973DD40F1D343F2F009D45DB /* libicudata.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD4041D343F2F009D45DB /* libicudata.a */; };
|
973DD40F1D343F2F009D45DB /* libicudata.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD4041D343F2F009D45DB /* libicudata.a */; };
|
||||||
973DD4101D343F2F009D45DB /* libicui18n.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD4051D343F2F009D45DB /* libicui18n.a */; };
|
973DD4101D343F2F009D45DB /* libicui18n.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD4051D343F2F009D45DB /* libicui18n.a */; };
|
||||||
@ -191,6 +192,7 @@
|
|||||||
9734E54D1D289D060061C39B /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Welcome.storyboard; path = "Kiwix-iOS/Storyboard/Welcome.storyboard"; sourceTree = SOURCE_ROOT; };
|
9734E54D1D289D060061C39B /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Welcome.storyboard; path = "Kiwix-iOS/Storyboard/Welcome.storyboard"; sourceTree = SOURCE_ROOT; };
|
||||||
973A5C911DEA3F5600C7804C /* CoreDataTableBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataTableBaseController.swift; sourceTree = "<group>"; };
|
973A5C911DEA3F5600C7804C /* CoreDataTableBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataTableBaseController.swift; sourceTree = "<group>"; };
|
||||||
973A5C931DEA6CA900C7804C /* URLResponseCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLResponseCache.swift; sourceTree = "<group>"; };
|
973A5C931DEA6CA900C7804C /* URLResponseCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLResponseCache.swift; sourceTree = "<group>"; };
|
||||||
|
973A5C981DEBC54800C7804C /* CloudKitOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CloudKitOperations.swift; sourceTree = "<group>"; };
|
||||||
973BCD001CEB3FA500F10B44 /* Kiwix_OSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Kiwix_OSXTests.swift; sourceTree = "<group>"; };
|
973BCD001CEB3FA500F10B44 /* Kiwix_OSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Kiwix_OSXTests.swift; sourceTree = "<group>"; };
|
||||||
973BCD021CEB3FA500F10B44 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
973BCD021CEB3FA500F10B44 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
973BCD0B1CEB3FA500F10B44 /* Kiwix_OSXUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Kiwix_OSXUITests.swift; sourceTree = "<group>"; };
|
973BCD0B1CEB3FA500F10B44 /* Kiwix_OSXUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Kiwix_OSXUITests.swift; sourceTree = "<group>"; };
|
||||||
@ -786,6 +788,7 @@
|
|||||||
97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */,
|
97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */,
|
||||||
9764CBD21D8083AA00072D6A /* ArticleOperation.swift */,
|
9764CBD21D8083AA00072D6A /* ArticleOperation.swift */,
|
||||||
970A2A211DD562CB0078BB7C /* BookOperations.swift */,
|
970A2A211DD562CB0078BB7C /* BookOperations.swift */,
|
||||||
|
973A5C981DEBC54800C7804C /* CloudKitOperations.swift */,
|
||||||
973208281DD223DB00EDD3DC /* RefreshLibrary.swift */,
|
973208281DD223DB00EDD3DC /* RefreshLibrary.swift */,
|
||||||
97D6811E1D6F70AC00E5FA99 /* ScanLocalBook.swift */,
|
97D6811E1D6F70AC00E5FA99 /* ScanLocalBook.swift */,
|
||||||
972F81561DDBFC79008D7289 /* Search.swift */,
|
972F81561DDBFC79008D7289 /* Search.swift */,
|
||||||
@ -1176,6 +1179,7 @@
|
|||||||
97A1FD261D6F71E200A80EE2 /* ZimReader.mm in Sources */,
|
97A1FD261D6F71E200A80EE2 /* ZimReader.mm in Sources */,
|
||||||
97A1FD1C1D6F71D800A80EE2 /* KiwixURLProtocol.swift in Sources */,
|
97A1FD1C1D6F71D800A80EE2 /* KiwixURLProtocol.swift in Sources */,
|
||||||
97C2C26A1DDCC58500A9CC64 /* ArticleOperation.swift in Sources */,
|
97C2C26A1DDCC58500A9CC64 /* ArticleOperation.swift in Sources */,
|
||||||
|
973A5C991DEBC54800C7804C /* CloudKitOperations.swift in Sources */,
|
||||||
973208261DD21E9C00EDD3DC /* CoreDataContainer.swift in Sources */,
|
973208261DD21E9C00EDD3DC /* CoreDataContainer.swift in Sources */,
|
||||||
97D6813F1D6F712800E5FA99 /* Article+CoreDataProperties.swift in Sources */,
|
97D6813F1D6F712800E5FA99 /* Article+CoreDataProperties.swift in Sources */,
|
||||||
97A1FD441D6F728200A80EE2 /* Preference.swift in Sources */,
|
97A1FD441D6F728200A80EE2 /* Preference.swift in Sources */,
|
||||||
|
@ -8,9 +8,12 @@
|
|||||||
|
|
||||||
import CoreData
|
import CoreData
|
||||||
import CoreSpotlight
|
import CoreSpotlight
|
||||||
|
import CloudKit
|
||||||
|
|
||||||
class Article: NSManagedObject {
|
class Article: NSManagedObject {
|
||||||
|
|
||||||
|
// MARK: - Fetch
|
||||||
|
|
||||||
class func fetch(url: URL, context: NSManagedObjectContext) -> Article? {
|
class func fetch(url: URL, context: NSManagedObjectContext) -> Article? {
|
||||||
guard let bookID = url.host,
|
guard let bookID = url.host,
|
||||||
let book = Book.fetch(bookID, context: context) else {return nil}
|
let book = Book.fetch(bookID, context: context) else {return nil}
|
||||||
@ -42,6 +45,8 @@ class Article: NSManagedObject {
|
|||||||
return fetch(request, type: Article.self, context: context) ?? [Article]()
|
return fetch(request, type: Article.self, context: context) ?? [Article]()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - CoreSpotlight
|
||||||
|
|
||||||
var searchableItem: CSSearchableItem {
|
var searchableItem: CSSearchableItem {
|
||||||
let attributeSet = CSSearchableItemAttributeSet()
|
let attributeSet = CSSearchableItemAttributeSet()
|
||||||
attributeSet.title = title
|
attributeSet.title = title
|
||||||
@ -54,7 +59,23 @@ class Article: NSManagedObject {
|
|||||||
return CSSearchableItem(uniqueIdentifier: url?.absoluteString, domainIdentifier: book?.id, attributeSet: attributeSet)
|
return CSSearchableItem(uniqueIdentifier: url?.absoluteString, domainIdentifier: book?.id, attributeSet: attributeSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Helper
|
// MARK: - CloudKit
|
||||||
|
|
||||||
|
var cloudKitRecord: CKRecord? {
|
||||||
|
guard let url = url, let bookID = book?.id else {return nil}
|
||||||
|
let recordID = CKRecordID(recordName: url.absoluteString)
|
||||||
|
let bookRecordID = CKRecordID(recordName: bookID)
|
||||||
|
let record = CKRecord(recordType: "Article", recordID: recordID)
|
||||||
|
record["path"] = path as NSString?
|
||||||
|
record["title"] = title as NSString?
|
||||||
|
record["snippet"] = snippet as NSString?
|
||||||
|
record["thumbImagePath"] = thumbImagePath as NSString?
|
||||||
|
record["isBookmarked"] = isBookmarked as NSNumber
|
||||||
|
record["book"] = CKReference(recordID: bookRecordID, action: .deleteSelf)
|
||||||
|
return record
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
var url: URL? {
|
var url: URL? {
|
||||||
guard let bookID = book?.id else {return nil}
|
guard let bookID = book?.id else {return nil}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import CoreData
|
import CoreData
|
||||||
|
import CloudKit
|
||||||
#if os(iOS) || os(watchOS) || os(tvOS)
|
#if os(iOS) || os(watchOS) || os(tvOS)
|
||||||
import UIKit
|
import UIKit
|
||||||
#elseif os(OSX)
|
#elseif os(OSX)
|
||||||
@ -16,7 +17,7 @@ import CoreData
|
|||||||
|
|
||||||
class Book: NSManagedObject {
|
class Book: NSManagedObject {
|
||||||
|
|
||||||
// MARK: - Add Book
|
// MARK: - Add
|
||||||
|
|
||||||
class func add(meta: [String: String], in context: NSManagedObjectContext) -> Book? {
|
class func add(meta: [String: String], in context: NSManagedObjectContext) -> Book? {
|
||||||
guard let id = meta["id"] else {return nil}
|
guard let id = meta["id"] else {return nil}
|
||||||
@ -74,15 +75,6 @@ class Book: NSManagedObject {
|
|||||||
return book
|
return book
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Properties
|
|
||||||
|
|
||||||
var url: URL? {
|
|
||||||
guard let meta4URL = meta4URL else {return nil}
|
|
||||||
var urlComponents = URLComponents(string: meta4URL.replacingOccurrences(of: ".meta4", with: ""))
|
|
||||||
urlComponents?.scheme = "https"
|
|
||||||
return urlComponents?.url
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Fetch
|
// MARK: - Fetch
|
||||||
|
|
||||||
class func fetchAll(in context: NSManagedObjectContext) -> [Book] {
|
class func fetchAll(in context: NSManagedObjectContext) -> [Book] {
|
||||||
@ -109,6 +101,34 @@ class Book: NSManagedObject {
|
|||||||
return fetch(fetchRequest, type: Book.self, context: context) ?? [Book]()
|
return fetch(fetchRequest, type: Book.self, context: context) ?? [Book]()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - CloudKit
|
||||||
|
|
||||||
|
var cloudKitRecord: CKRecord {
|
||||||
|
let recordID = CKRecordID(recordName: id)
|
||||||
|
let record = CKRecord(recordType: "Book", recordID: recordID)
|
||||||
|
record["id"] = id as NSString?
|
||||||
|
record["title"] = title as NSString?
|
||||||
|
record["description"] = desc as NSString?
|
||||||
|
record["creator"] = creator as NSString?
|
||||||
|
record["publisher"] = publisher as NSString?
|
||||||
|
record["favicon"] = favIcon as NSData?
|
||||||
|
record["date"] = date as NSDate?
|
||||||
|
record["articleCount"] = articleCount as NSNumber
|
||||||
|
record["mediaCount"] = mediaCount as NSNumber
|
||||||
|
record["fileSize"] = fileSize as NSNumber
|
||||||
|
record["language"] = language?.code as NSString?
|
||||||
|
return record
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
var url: URL? {
|
||||||
|
guard let meta4URL = meta4URL else {return nil}
|
||||||
|
var urlComponents = URLComponents(string: meta4URL.replacingOccurrences(of: ".meta4", with: ""))
|
||||||
|
urlComponents?.scheme = "https"
|
||||||
|
return urlComponents?.url
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Manage
|
// MARK: - Manage
|
||||||
|
|
||||||
func removeResumeData() {
|
func removeResumeData() {
|
||||||
|
20
Kiwix/Operations/CloudKitOperations.swift
Normal file
20
Kiwix/Operations/CloudKitOperations.swift
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// CloudKitOperations.swift
|
||||||
|
// Kiwix
|
||||||
|
//
|
||||||
|
// Created by Chris Li on 11/27/16.
|
||||||
|
// Copyright © 2016 Chris Li. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import CloudKit
|
||||||
|
import ProcedureKit
|
||||||
|
|
||||||
|
class BookmarkSyncOperation: Procedure {
|
||||||
|
let articleURL: URL
|
||||||
|
|
||||||
|
init(articleURL: URL) {
|
||||||
|
self.articleURL = articleURL
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user