I'm using Parse in my iOS app.
In my app I'm using a lot of saveEventually()
functions to store data in Parse without there needing to be an internet connection available.
I know that saveEventually()
returns a BFTask
object.
It is possible to get all the tasks created in order to check their status in any given moment? Also, could this same technique be used after an app restart?
Thanks!
Asked
Active
Viewed 166 times
0

egor.zhdan
- 4,555
- 6
- 39
- 53

mattiad
- 13
- 1
- 6
1 Answers
0
Parse is using Boltz framework, which in return, you will have a BFTask object upon completion.
Example:
yourPFObject.saveEventually().continueWithBlock {
(task: BFTask!) -> BFTask in
if task.isCancelled() {
// the save was cancelled.
} else if task.error() {
// the save failed.
} else {
// the object was saved successfully.
var object = task.result() as PFObject
}
}
With this in mind, you can check their status by storing the completed task in coredata. In appDelegate applicationDidBecomeActive or didFinishLaunchingWithOptions, you can attempt to retrieve them from coredata depending on your logic.
Of course if you want to just keep track on the status, you can keep in a dictionary and stores in NSUserDefault. It is completely up to your choice and needs.
More example can be found in this link : https://github.com/BoltsFramework/Bolts-iOS

Francis Yeap
- 284
- 2
- 10
-
My target is check the task status changing (completed propery) after some period or after app restart. If i save BFTask in NSUserDefault, can i check the status changes yet ? – mattiad Oct 08 '15 at 04:28
-
You add a flag in 'NSUserDefault' and check the flag everytime 'applicationDidBecomeActive' is called. Like i mentioned, the implementation, whether in NSUserDefault/CoreData and the type of data you want to store is completely up to you. – Francis Yeap Oct 08 '15 at 08:09
-
Is not possible to save an array of BFTask objects in NSUserDefault, because the content of array MUST to be a "property-list" type or NSdata type. And i can not transform in NSData because require subclass BFTask to use initWithCoder method. https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/#//apple_ref/occ/instm/NSUserDefaults/setObject:forKey: – mattiad Oct 09 '15 at 17:11
-
You don't have to save the BFTask as NSUserDefault 'directly'. That is, you can set the BFTask's task to its original type, `String` for example, and save it there. It's all about the logic and what you trying to achieve. – Francis Yeap Oct 12 '15 at 02:46
-
And actually, i did not mention anything about saving `BFTask` in NSUserDefaults. If you read my answer properly, i suggested to keep a **dictionary of values** and **stores in NSUserDefault** – Francis Yeap Oct 12 '15 at 02:48
-
This no help me, because if i save a simple String or Bool in NSUserDefault, when i restart the App, where i can found the original tasks to compare the NSUserDefault result ? ... In other words my real target is check if all saveEventually() tasks are completed before perform some other operation on the parse cloud. – mattiad Oct 12 '15 at 11:49
-
I'm genuinely interested in whether this is somehow a viable path. How *are* you supposed to retrieve a BFTask using an NSString or NSNumber? – Darren Black Oct 13 '16 at 13:34