Fix: Network Observer not balance

This commit is contained in:
Chris Li 2016-09-20 13:22:20 -04:00
parent cd9c4d4c58
commit 987c633a14
3 changed files with 15 additions and 11 deletions

View File

@ -49,7 +49,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.8.900</string>
<string>1.8.912</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.903</string>
<string>1.8.915</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>

View File

@ -15,10 +15,15 @@ class RefreshLibraryOperation: GroupOperation {
private(set) var firstTime = false
init(invokedByUser: Bool = false) {
let retrive = Retrive()
let retrieve = Retrieve()
let process = Process()
process.injectResultFromDependency(retrive)
super.init(operations: [retrive, process])
process.injectResultFromDependency(retrieve)
super.init(operations: [retrieve, process])
addObserver(NetworkObserver())
if UIApplication.sharedApplication().applicationState == .Active {
addCondition(ReachabilityCondition(url: Retrieve.url))
}
addObserver(WillExecuteObserver { _ in
(UIApplication.sharedApplication().delegate as! AppDelegate).registerNotification()
@ -32,20 +37,18 @@ class RefreshLibraryOperation: GroupOperation {
}
}
private class Retrive: Operation, ResultOperationType {
private class Retrieve: Operation, ResultOperationType {
private static let url = NSURL(string: "https://download.kiwix.org/library/library.xml")!
private var result: NSData?
override init() {
super.init()
addObserver(NetworkObserver())
if UIApplication.sharedApplication().applicationState == .Active {
addCondition(ReachabilityCondition(url: Retrive.url))
}
name = "Library Retrieve"
}
private override func execute() {
let task = NSURLSession.sharedSession().dataTaskWithURL(Retrive.url) { (data, response, error) in
guard !cancelled else {return}
let task = NSURLSession.sharedSession().dataTaskWithURL(Retrieve.url) { (data, response, error) in
self.result = data
self.finish()
}
@ -66,6 +69,7 @@ private class Process: Operation, NSXMLParserDelegate, AutomaticInjectionOperati
context.parentContext = NSManagedObjectContext.mainQueueContext
context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
super.init()
name = "Library Process"
}
override private func execute() {