cloud kit try

This commit is contained in:
Chris Li 2016-10-12 16:17:32 -04:00
parent decd800275
commit dd00ebecf7
6 changed files with 62 additions and 30 deletions

View File

@ -49,7 +49,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.8.1688</string>
<string>1.8.1706</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.1688</string>
<string>1.8.1707</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>

View File

@ -693,6 +693,7 @@
975334CD1CEB6A78007ED50B /* Others */,
931D277C156AE671D3F9EADA /* Frameworks */,
F544A4E4357A6D33CF234C6B /* Pods */,
9C1D0054BEA442431151A95D /* Products */,
);
sourceTree = "<group>";
};
@ -796,6 +797,13 @@
path = "Kiwix-iOSWidgets";
sourceTree = "<group>";
};
9C1D0054BEA442431151A95D /* Products */ = {
isa = PBXGroup;
children = (
);
name = Products;
sourceTree = "<group>";
};
CFDF64EC6F9DB861DEEB91A0 /* Frameworks */ = {
isa = PBXGroup;
children = (
@ -955,8 +963,11 @@
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 97A2AB7F1C1B80FF00052E74;
productRefGroup = 97A2AB891C1B80FF00052E74 /* Products */;
productRefGroup = 9C1D0054BEA442431151A95D /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (

View File

@ -91,32 +91,53 @@ class BookmarkCloudKitOperation: Operation {
}
override func execute() {
guard let bookID = article.book?.id else {finish(); return}
let recordID = CKRecordID(recordName: bookID + "|" + article.path)
let database = CKContainer(identifier: "iCloud.org.kiwix").privateCloudDatabase
database.fetchRecordWithID(recordID) { (record, error) in
if let record = record {
if self.article.isBookmarked {
self.populate(record, with: self.article)
database.saveRecord(record, completionHandler: { (record, error) in
self.finish()
})
} else {
database.deleteRecordWithID(recordID, completionHandler: { (recordID, error) in
self.finish()
})
}
} else {
guard self.article.isBookmarked else {self.finish(); return}
let record = CKRecord(recordType: "Article", recordID: recordID)
self.populate(record, with: self.article)
database.saveRecord(record, completionHandler: { (record, error) in
self.finish()
})
}
// guard let bookID = article.book?.id else {finish(); return}
// let container = CKContainer(identifier: "iCloud.org.kiwix")
// container.accountStatusWithCompletionHandler { (status, error) in
// guard status == .Available else {self.finish(); return}
//
// container.fetchUserRecordIDWithCompletionHandler({ (recordID, error) in
// guard let ownerName = recordID?.recordName else {self.finish(); return}
// let database = container.privateCloudDatabase
// let zoneID = CKRecordZoneID(zoneName: bookID, ownerName: ownerName)
// database.fetchRecordZoneWithID(zoneID, completionHandler: { (zone, error) in
// if let zone = zone {
//
// } else {
// database.
// }
// })
// })
}
// guard let bookID = article.book?.id else {finish(); return}
//
// let recordID = CKRecordID(recordName: bookID + "|" + article.path)
// let database = CKContainer(identifier: "iCloud.org.kiwix").privateCloudDatabase
//
// database.fetchRecordWithID(recordID) { (record, error) in
// if let record = record {
// if self.article.isBookmarked {
// self.populate(record, with: self.article)
// database.saveRecord(record, completionHandler: { (record, error) in
// self.finish()
// })
// } else {
// database.deleteRecordWithID(recordID, completionHandler: { (recordID, error) in
// self.finish()
// })
// }
// } else {
// guard self.article.isBookmarked else {self.finish(); return}
// let record = CKRecord(recordType: "Article", recordID: recordID)
// self.populate(record, with: self.article)
// database.saveRecord(record, completionHandler: { (record, error) in
// self.finish()
// })
// }
// }
}
func populate(record: CKRecord, with article: Article) {

View File

@ -12,7 +12,7 @@ pod 'Operations', :git => 'https://github.com/ProcedureKit/ProcedureKit.git', :b
end
target 'Kiwix-OSX' do
target 'Kiwix-macOS' do
platform :osx, '10.10'

View File

@ -28,6 +28,6 @@ SPEC CHECKSUMS:
Operations: 6a33d325dae88de21b8edc69b9884fce01aea22b
SwiftyUserDefaults: 7abdba50a50ea0c18ee8903af3c88e4c1cb8448d
PODFILE CHECKSUM: 7fce2ab788d4fea2728405e44965e38a852f02db
PODFILE CHECKSUM: e345ab565b0ce78937afe5c9543a0acc00375442
COCOAPODS: 1.0.1