NSURLSessionDataTask with over 8000 requests

hi i need to create a while cycle wheren for each value of array make a POST REST CALL to php url


i using this code inside while cycle


NSURLSessionDataTask *task = [session dataTaskWithRequest:request

completionHandler:

^(NSData *data, NSURLResponse *response, NSError *error)



this wors with total items about 1000-1200 but if i try with 2000 or 4000 post this give error


Error Domain=NSURLErrorDomain Code=-1001 "Tempo di richiesta scaduto." UserInfo={NSUnderlyingError=0x1c7056080 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http://storage.vanigliapro.it/test.php, NSErrorFailingURLKey=http://storage.vanigliapro.it/test.php, _kCFStreamErrorDomainKey=4,


what can i do for make all requests?

Replies

You are doing all your request concurrently (At the same time), with 8000 request simultaneously you get error:


Request time expired


You need to limit the number of request that you do at the same time.


You have several options:


- Use NSOperationQueue and set maxConcurrentOperationCount to a suitable number of NSOperations,


- Use a Serial Queue and dispatch_sync() each request so the caller waits for the code to be completed.