I have already successfully implemented NSOperationQueue in the application.
I have one operation queue that can have 1000 NSOperations, as shown below.
@interface Operations : NSOperation @end @implementation Operations - (void)main { NSURL *url = [NSURL URLWithString:@"Your URL Here"]; NSString *contentType = @"application/json"; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSError *err = nil; NSData *body = [NSJSONSerialization dataWithJSONObject:postVars options:NSJSONWritingPrettyPrinted error:&err]; [request setHTTPBody:body]; [request addValue:[NSString stringWithFormat:@"%lu", (unsigned long)body.length] forHTTPHeaderField: @"Content-Length"]; [request setTimeoutInterval:60]; NSHTTPURLResponse *response = nil; NSError *error = nil; NSData *resData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; } @end
Now for this queue, I add all 1000 operations at a time. I am adding an operation as shown below.
Operations *operation = [[Operations alloc]init]; [downloadQueue addOperation:operation];
Now what happens, the time interval is 60 as [request setTimeoutInterval:60]
So, think that after 60 seconds, if 300 operations out of 1000 operations have ended, another 700 operations will cause a request timeout error.
So what should I do in this case.
Is it possible to resume unsuccessful operations? Or should I perform the operation again and add it to the queue.
Is there a better mechanism than this?
source share