Reputation: 1732
This has perplexed me for some time now so any advice would be appreciated.
I have 10 NSURLSessionUploadTasks
started at the same time and happening asynchronously from my viewDidLoad
:
[self uploadMainInformation];
[self uploadSubInformation];
[self uploadLocation];
[self uploadMainPhoto];
[self uploadSubPhoto1];
[self uploadSubPhoto2];
etc. I am using an array to say when the tasks are complete by using completion handlers. However, I'm stumped as to how to poll the array to find out when it is empty. Adding and removing at the start and end of each session start and end is easy. I just have no idea how to poll for an empty array.
Is it possible to track when the NSMutableArray
is empty? Or is there a better solution of which I don't know and can't seem to find? I simply wish to start 10 simultaneous uploads and know when they have all (successfully) completed.
Thanks in advance for any assistance. It's driving me nuts.
Upvotes: 0
Views: 101
Reputation: 17720
Set a delegate on your NSURLSession
, and add the method:
- (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session;
Upvotes: 1
Reputation: 14068
Why so complicated with the array? Just add a counter, a simple int, increment it when you fire a request and decrement it when a request is finished or ran into an error. They are all complete when the value of your counter is back to 0.
Anyway, an NSArray
is empty when its count
method returns 0.
Upvotes: 0