Both of the following questions are being asked in context to maintain NSOperationQueue and NSInvocationOperation.
As I have used this concept to download multiple videos, how do I remove/release added NSInvocationOperation from NSOperationQueue after completion of downloading a video?
And also, what should I do if in case I want to stop to download specific video while the process of downloading in progress?
how do I remove/release added NSInvocationOperation from NSOperationQueue after completion of downloading a video?
The operation is automatically removed from the queue when it has finished i.e. when -isFinished returns true.
And also, what should I do if in case I want to stop to download specific video while the process of downloading in progress?
When you want to stop an operation part way through, you must send it the -cancel message. However this will not magically stop the operation from running. Your task needs to periodically check if it is cancelled and finish itself if it turns out that it has been. So you need to download your video in chunks and check the operation's cancelled status after each chunk. The following pseudocode might help:
while (![myOperation isCancelled] && thereIsMoreData)
{
download a chunk of data and save it
}
This means, for instance, you can't use NSURLConnection
's -sendSynchronousRequest:returningResponse:error:
to get the data because it won't be able to check the cancelled status of the operation until after all the data is already downloaded.
After an NSOperation performed that task to completion, it will be automatically removed from the queue. Ref link.
Make sub-class of NSOperation. Keep an identifier for each operation. Store all the operations in array. When u dont want an operation to continue, just give cancel message to the operation , ie., [_operation cancel];
来源:https://stackoverflow.com/questions/6827203/how-to-remove-cancel-nsinvocationoperation-from-nsoperationqueue