This commit is contained in:
Chris Li 2016-12-23 16:55:08 -05:00
parent 05ec52d535
commit 4ca9ba78f0
9 changed files with 115 additions and 125 deletions

View File

@ -49,7 +49,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.8.3635</string>
<string>1.8.3667</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>

View File

@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.8.3635</string>
<string>1.8.3682</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>

View File

@ -1307,7 +1307,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@ -1349,7 +1349,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

View File

@ -13,37 +13,5 @@
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Kiwix/Operations/CloudKit.swift"
timestampString = "502151859.112083"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "89"
endingLineNumber = "89"
landmarkName = "execute()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Kiwix/Operations/CloudKit.swift"
timestampString = "502151861.497788"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "95"
endingLineNumber = "95"
landmarkName = "execute()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View File

@ -113,17 +113,6 @@ class Book: NSManagedObject {
//
// var record: CKRecord {
// 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
// }

View File

@ -23,43 +23,54 @@ class BookmarkSyncOperation: GroupProcedure {
super.init(operations: [zone, book])
}
}
//class UpdateArticleOperation: Procedure {
// let database: CKDatabase
// let bookID: String
//
// init(database: CKDatabase, bookID: String) {
// self.database = database
// self.bookID = bookID
// super.init()
// }
//
// override func execute() {
// guard let zone = requirement.value else {
// finish()
// return
// }
//
// AppDelegate.persistentContainer.performBackgroundTask { (context) in
// guard let book = Book.fetch(self.bookID, context: context) else {
// self.finish()
// return
// }
// let fetch = CKFetchRecordsOperation(recordIDs: [bookRecordID])
// fetch.database = self.database
// fetch.fetchRecordsCompletionBlock = { records, error in
// if let book = records?[bookRecordID] {
//
// }
// }
// }
//
//
// }
//}
class FetchArticleRecordOperation: Procedure {
let database: CKDatabase
let articleURL: URL
var recordZone: CKRecordZone?
var bookRecord: CKRecord?
var articleRecord: CKRecord?
init(database: CKDatabase, articleURL: URL) {
self.database = database
self.articleURL = articleURL
super.init()
}
override func execute() {
guard let zone = recordZone, let bookRecord = bookRecord else {
finish()
return
}
let recordID = CKRecordID(recordName: articleURL.absoluteString, zoneID: zone.zoneID)
let fetch = CKFetchRecordsOperation(recordIDs: [recordID])
fetch.database = self.database
fetch.fetchRecordsCompletionBlock = { records, error in
if let record = records?[recordID] {
// self.article = record
self.finish()
} else {
self.create(recordID: recordID, in: zone)
}
}
CloudKitQueue.shared.add(operations: fetch)
}
private func create(recordID: CKRecordID, in zone: CKRecordZone) {
let record = CKRecord(recordType: "Article", recordID: recordID)
let context = AppDelegate.persistentContainer.newBackgroundContext()
}
private func configure(record: CKRecord, article: Article) {
}
}
class FetchBookRecordOperation: Procedure {
let database: CKDatabase
@ -78,32 +89,51 @@ class FetchBookRecordOperation: Procedure {
finish()
return
}
AppDelegate.persistentContainer.performBackgroundTask { (context) in
let recordID = CKRecordID(recordName: self.bookID, zoneID: zone.zoneID)
let fetch = CKFetchRecordsOperation(recordIDs: [recordID])
fetch.database = self.database
fetch.fetchRecordsCompletionBlock = { records, error in
if let record = records?[recordID] {
self.record = record
// update, or not
self.finish()
} else {
let record = CKRecord(recordType: "Book", recordID: recordID)
let modify = CKModifyRecordsOperation(recordsToSave: [record], recordIDsToDelete: nil)
modify.database = self.database
modify.modifyRecordsCompletionBlock = { saved, _, error in
if let record = saved?.first {
self.record = record
self.finish()
} else {
self.finish(withError: error)
}
}
CloudKitQueue.shared.add(operations: modify)
}
let recordID = CKRecordID(recordName: self.bookID, zoneID: zone.zoneID)
let fetch = CKFetchRecordsOperation(recordIDs: [recordID])
fetch.database = self.database
fetch.fetchRecordsCompletionBlock = { records, error in
if let record = records?[recordID] {
self.record = record
self.finish()
} else {
self.create(recordID: recordID, in: zone)
}
CloudKitQueue.shared.add(operations: fetch)
}
CloudKitQueue.shared.add(operations: fetch)
}
private func create(recordID: CKRecordID, in zone: CKRecordZone) {
let record = CKRecord(recordType: "Book", recordID: recordID)
let context = AppDelegate.persistentContainer.newBackgroundContext()
context.performAndWait {
guard let book = Book.fetch(self.bookID, context: context) else {return}
record["id"] = book.id as NSString?
record["title"] = book.title as NSString?
record["description"] = book.desc as NSString?
record["creator"] = book.creator as NSString?
record["publisher"] = book.publisher as NSString?
record["favicon"] = book.favIcon as NSData?
record["date"] = book.date as NSDate?
record["articleCount"] = book.articleCount as NSNumber
record["mediaCount"] = book.mediaCount as NSNumber
record["fileSize"] = book.fileSize as NSNumber
record["language"] = book.language?.code as NSString?
}
let modify = CKModifyRecordsOperation(recordsToSave: [record], recordIDsToDelete: nil)
modify.database = self.database
modify.modifyRecordsCompletionBlock = { saved, _, error in
if let record = saved?.first {
self.record = record
self.finish()
} else {
self.finish(withError: error)
}
}
CloudKitQueue.shared.add(operations: modify)
}
}

View File

@ -36,9 +36,8 @@ fileprivate class Retrieve: NetworkDataProcedure<URLSession> {
}
}
fileprivate class Process: Procedure, ResultInjection, XMLParserDelegate {
var requirement: PendingValue<HTTPResult<Data>> = .pending
fileprivate(set) var result: PendingValue<Void> = .void
fileprivate class Process: Procedure, InputProcedure, XMLParserDelegate {
var input: Pending<HTTPPayloadResponse<Data>> = .pending
private let context: NSManagedObjectContext
private var storeBookIDs = Set<String>()
@ -54,7 +53,7 @@ fileprivate class Process: Procedure, ResultInjection, XMLParserDelegate {
}
override func execute() {
guard let data = requirement.value?.payload else {
guard let data = input.value?.payload else {
finish(withError: ProcedureKitError.requirementNotSatisfied())
return
}

View File

@ -8,8 +8,9 @@ platform :ios, '10.0'
pod 'DZNEmptyDataSet'
pod 'MBProgressHUD', '~> 1.0.0'
pod 'SwiftyUserDefaults'
pod 'ProcedureKit', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.4'
pod 'ProcedureKit/Network', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.4'
pod 'ProcedureKit/Mobile', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.4'
pod 'ProcedureKit', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.6'
pod 'ProcedureKit/Cloud', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.6'
pod 'ProcedureKit/Network', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.6'
pod 'ProcedureKit/Mobile', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :branch => 'release/4.0.0.beta.6'
end

View File

@ -1,39 +1,42 @@
PODS:
- DZNEmptyDataSet (1.8.1)
- MBProgressHUD (1.0.0)
- ProcedureKit (4.0.0.beta.4):
- ProcedureKit/Standard (= 4.0.0.beta.4)
- ProcedureKit/Mobile (4.0.0.beta.4):
- ProcedureKit (4.0.0.beta.5):
- ProcedureKit/Standard (= 4.0.0.beta.5)
- ProcedureKit/Cloud (4.0.0.beta.5):
- ProcedureKit/Standard
- ProcedureKit/Network (4.0.0.beta.4):
- ProcedureKit/Mobile (4.0.0.beta.5):
- ProcedureKit/Standard
- ProcedureKit/Standard (4.0.0.beta.4)
- ProcedureKit/Network (4.0.0.beta.5):
- ProcedureKit/Standard
- ProcedureKit/Standard (4.0.0.beta.5)
- SwiftyUserDefaults (3.0.0)
DEPENDENCIES:
- DZNEmptyDataSet
- MBProgressHUD (~> 1.0.0)
- ProcedureKit (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.4`)
- ProcedureKit/Mobile (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.4`)
- ProcedureKit/Network (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.4`)
- ProcedureKit (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.5`)
- ProcedureKit/Cloud (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.5`)
- ProcedureKit/Mobile (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.5`)
- ProcedureKit/Network (from `https://github.com/ProcedureKit/ProcedureKit.git`, branch `release/4.0.0.beta.5`)
- SwiftyUserDefaults
EXTERNAL SOURCES:
ProcedureKit:
:branch: release/4.0.0.beta.4
:branch: release/4.0.0.beta.5
:git: https://github.com/ProcedureKit/ProcedureKit.git
CHECKOUT OPTIONS:
ProcedureKit:
:commit: be78bf8bea9928ad24bf6b83bc7b5cfab11b5874
:commit: e0d3e52f5052b1004f07e7d595022fc54d6e5336
:git: https://github.com/ProcedureKit/ProcedureKit.git
SPEC CHECKSUMS:
DZNEmptyDataSet: 9525833b9e68ac21c30253e1d3d7076cc828eaa7
MBProgressHUD: 4890f671c94e8a0f3cf959aa731e9de2f036d71a
ProcedureKit: 9160071e54e3885fad82f72acc8474366c764f5b
ProcedureKit: 71bf6e0265e406f96bdd4f767ef47c78a2c18ce3
SwiftyUserDefaults: 0f1d45fc3aafb9064dac661e367f8f83fe21a4b4
PODFILE CHECKSUM: 43f01172d4e3b5f4e0ad68f2a251cc23a4bb0f5a
PODFILE CHECKSUM: abf95d1f5f7b05e5b977e17595badfbae0a1b862
COCOAPODS: 1.0.1