nsoperation

iOS - How to know when NSOperationQueue finish processing a few operations?

天大地大妈咪最大 提交于 2019-11-28 04:47:05
I need in my application to download directories and their content. So I decided to implement a NSOperationQueue and I subclassed NSOperation to implement NSURLRequest etc... The problem is I add all the operations at once and I can't figure out when all the files for one directory are downloaded in order to update the UI and enable this specific directory. Now I have to wait that all the files from all the directories are downloaded in order to update the UI. I already implemented key-value observing for the operationCount of the NSOperationQueue and the isFinished of the NSOperation but I

Asynchronous methods in NSOperation

£可爱£侵袭症+ 提交于 2019-11-28 04:31:10
I'm fetching some data from Facebook Connect (using the FBConnect Objective-C 2.0 framework) and I'm doing all that in an NSOperation. It is in an NSOperation because I have several other operations that run as well and this is one of them. The problem is that all the FBConnect calls are asynchronous. Because of this, the main method of the NSOperation quickly finishes and the operation is marked as completed. Is there some way to overcome this? It would appear there are no synchronous options in FBConnect! Many thanks, Mike Below is a full example. In your subclass, after your async method

Which tasks are more suitable to NSOperation than GCD? [duplicate]

醉酒当歌 提交于 2019-11-28 03:50:17
This question already has an answer here: NSOperation vs Grand Central Dispatch 8 answers Which tasks would be better suited to using NSOperation as opposed to using GCD when programming for the iPhone? To me they seem to do the same thing. I can't see the strengths and weaknesses one has over the other. NSOperation is built on top of GCD, so the question is more about whether you use NSOperation or pass a block directly to GCD. An NSOperation is bulky and needs more boiler-plate codes to set it up, but it has a lot more functionality. You can create the same NSOperation subclass in various

Default value of maxConcurrentOperationCount for NSOperationQueue

十年热恋 提交于 2019-11-27 23:28:14
As the title suggests, what is the default value of the maxConcurrentOperationCount for NSOperationQueue? Is it set to a value of 1? From the documentation , The maximum number of concurrent operations set explicitly on the receiver using the setMaxConcurrentOperationCount: method. If no value has been explicitly set, this method returns NSOperationQueueDefaultMaxConcurrentOperationCount by default . So it is NSOperationQueueDefaultMaxConcurrentOperationCount . If this is set, it will choose an appropriate value based on the number of available processors and other relevant factors. This is

NSOperation wait until asynchronous block executes

南笙酒味 提交于 2019-11-27 21:13:30
问题 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,

Application sticks on OSSpinLockLockSlow

南笙酒味 提交于 2019-11-27 19:53:59
Update 2: I found a workaround which is to synchronize MOC deallocating and saving. Please see the updated project. https://github.com/shuningzhou/MOCDeadLock.git Note: I made it fail more aggressively. Don't run it on a real device! Update: A sample project to demonstrate this issue. https://github.com/shuningzhou/MOCDeadLock.git XCode 6.2: Unable to reproduce. XCode 6.3: Reproducible. XCode 6.4 beta: Reproducible. ========================== The Issue =============================== Our app randomly stuck on OSSpinLockLockSlow after upgrading to XCode 6.3. In our project, we used NSOperation

How to immediately force cancel an NSOperation with AFNetworking?

女生的网名这么多〃 提交于 2019-11-27 18:57:07
问题 I am using AFNetworking in my application and I am attempting to implement a "Tap To Cancel" feature in my progress HUD. I have a singleton class that manages all of the HTTP requests. If the progress HUD is tapped, I call: [[[HTTPRequestSingleton sharedClient] operationQueue] cancelAllOperations]; But this doesn't "cancel" the operation like I need it to. I read up on the NSOperationQueue docs and came across this: Canceling an operation object leaves the object in the queue but notifies the

Proper way to deal with cell reuse with background threads?

丶灬走出姿态 提交于 2019-11-27 17:15:50
I have a UICollectionView , but the same methods should apply to UITableViews . Each of my cells contains an image I load from disk, which is a slow operation. To mitigate this, I use an async dispatch queue. This works fine, but quickly scrolling results in these operations stacking up, such that the cell will change its image from one to another in sequence, until finally stopping at the last call. In the past, I've done a check to see if the cell was still visible, and if not I don't continue. However, this is not working with UICollectionView, and anyway it is not efficient. I am

Continue operation when app did enter background on iOS

我是研究僧i 提交于 2019-11-27 15:10:17
问题 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

Asynchronous NSURLConnection with NSOperation

我怕爱的太早我们不能终老 提交于 2019-11-27 12:29:09
I want to do NSURLConnection in background mode,because it response is having much data.Forums are telling to use Apple's finite length coding to use in didEnterBackground . but I want to avoid it.instead of it I use following code through NSOperation with NSInvocation as, but it is not working. connectToServer is having NSURLConnection operation.any help please? didReceiveData , didReceiveResponse delegate methods are not called? NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector