nsoperation

Continue operation when app did enter background on iOS

安稳与你 提交于 2019-11-29 00:10:41
in my app i have some NSOperation that update some core data element from a online database, sometime the update require some minute, and when the screen of iPhone lock, the app enter in the background mode, and this update is stopped, so i have to reopen the app to continue the update, so i have search a lot on stack overflow and i have find some information about: beginBackgroundTaskWithExpirationHandler that is a method from apple that let continue some task also when the app is in the background mode, and i have do this: - (void)applicationDidEnterBackground:(UIApplication *)application {

NSOperation wait until asynchronous block executes

ⅰ亾dé卋堺 提交于 2019-11-28 23:22:48
i need to put asynchronous operations into an operation queue, however, they need to execute on after the other self.operationQueue = [NSOperationQueue new]; self.operationQueue.maxConcurrentOperationCount = 1; [self.operationQueue addOperationWithBlock:^{ // this is asynchronous [peripheral1 connectWithCompletion:^(NSError *error) { }]; }]; [self.operationQueue addOperationWithBlock:^{ // this is asynchronous [peripheral2 connectWithCompletion:^(NSError *error) { }]; }]; the problem is, since peripheralN connectWithCompletion is asynchronous, the operation in queue is ended and the next is

how to cancel out of operation created with addOperationWithBlock?

北城余情 提交于 2019-11-28 23:16:49
I'm using NSOperationQueue's addOperationWithBlock. From within the block, how do I check to see if I'm supposed to cancel the operation? Or access any NSOperation properties/methods? [myOperationQueue addOperationWithBlock: ^{ while ( /* long running loop */ ) { // how to determine here if I need to cancel? // for that matter, access any NSOperation properties/methods? } }]; Is the better way to do this to use a NSBlockOperation? A better solution might be to use NSBlockOperation and add that to the queue instead of a raw block. You could do something like: __block NSBlockOperation *operation

Why does NSOperation disable automatic key-value observing?

∥☆過路亽.° 提交于 2019-11-28 17:56:34
When working with a custom NSOperation subclass I noticed that the automatic key-value observing is disabled by the [NSOperation automaticallyNotifiesObserversForKey] class method (which returns NO at least for some key paths). Because of that the code inside of NSOperation subclasses is littered by manual calls to willChangeValueForKey: and didChange… , as visible in many code samples on the web. Why does NSOperation do that? With automatic KVO support people could simply declare properties for the operation lifecycle flags ( isExecuting etc.) and trigger the KVO events through the accessors,

How do I do an Asynchronous NSURLConnection inside an NSOperation?

给你一囗甜甜゛ 提交于 2019-11-28 17:18:24
I want to do an Asynchrous NSURLConnection inside of an NSOperation on a background thread. (it is because I'm doing some very expensive operations on the data as they come back that want to be done as the data comes in and in background) Here is my first attempt: IN my AppDelegate: // create the opperation and add it to the queue: self.sharedOperationQueue = [[[NSOperationQueue alloc] init] autorelease]; LibXMLOperation *op = [[[LibXMLOperation alloc] init] autorelease]; [self.sharedOperationQueue addOperation:op]; Here is my operation: @interface EbirdLibXMLOperation : NSOperation { @private

NSOperation and NSNotificationCenter on the main thread

送分小仙女□ 提交于 2019-11-28 16:44:44
I have an NSOperation. When it is finished I fire a NSNotificationCenter to let the program know that the NSoperation is finished and to update the gui. To my understanding listeners to the NSNotification will not run on the main thread because the NSOperation is not on the main thread. How can I make it so that the listeners run on the main thread when I fire my event? [[NSNotificationCenter defaultCenter] postNotificationName:@"myEventName" object:self]; You can use performSelectorOnMainThread:withObject:waitUntilDone: with using a helper method, in a similar fashion to the following example

Best practice to send a lot of data in background on iOS4 device?

对着背影说爱祢 提交于 2019-11-28 16:44:08
I have an app that needs to send data (using POST) to a server. This function has to be on one of the NavigationController sub-controllers and user should be able to navigate away from this controller and/or close the app (only iPhone4/iOS4 will be supported). Should I use threads/NSOperations or/and send data using existing asynchronous methods? Any ideas/best practices how to implement this? OK, I'll answer my own question. First, like tc said, it's better to have this call on the application delegate, so that the View in the NavigationController can be closed. Second, mark beginning of the

NSOperation - Forcing an operation to wait others dynamically

拜拜、爱过 提交于 2019-11-28 16:33:13
I am trying to implement an operation queue and I have the following scenario: NSOperation A NSOperation B NSOperation C NSOperation D NSOperationQueue queue I start adding A to queue . During the execution of A I need to get some data from B and I can't continue with A until B returns what I need. The same situation will occur for B depending on C and for C depending on D . To manage this, at each NSOperation I have this code: NSOperation *operation; //This can be A, B, C, D or any other NSOperation [self setQueuePriority:NSOperationQueuePriorityVeryLow]; //Set the current NSOperation with

Do NSOperations and their completionBlocks run concurrently?

[亡魂溺海] 提交于 2019-11-28 12:31:32
I've got a bunch of NSOperations added to a NSOperationQueue . The operation queue has the maxConcurrentOperationCount set to 1, so that the NSOperations run one after the other. Now, in the completionBlock of a NSOperation I want to cancel all pending NSOperations by calling cancelAllOperations on the NSOperationQueue . Is it safe to do this? Can I be sure that the start -method of the next operation is called only after the completionBlock of the previous operation has been fully executed? Or do the completionBlock of the previous operation and the task of the current operation run

NSBlockOperation or NSOperation with ALAsset Block to display photo-library images using ALAsset URL

半城伤御伤魂 提交于 2019-11-28 11:46:46
I am asking this question regarding my questions Display photolibrary images in an effectual way iPhone and Highly efficient UITableView "cellForRowIndexPath" method to bind the PhotoLibrary images . So I would like to request that answers are not duplicated to this one without reading the below details :) Let's come to the issue, I have researched detailed about my above mentioned issue, and I have found the document about operation queues from here . So I have created one sample application to display seven photo-library images using operation queues through ALAsset blocks. Here are the