简体   繁体   中英

Tracking when a number of NSURLSessions have completed

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.

在您的NSURLSession上设置一个委托,并添加方法:

- (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM