0
votes

I have a situation where I need to download multiple files sequentially as each download depends on its previous downloaded file. (I am processing the file in background itself)

I am using NSURLSessionConfiguration backgroundSessionConfiguration.

There is a scenario where NSURLSessionDownloadTask initiates while the application is in background. This crashes the app with Assertion permittedbackgroundduration.

So, my question is, am I doing wrong by initiating the download task in background???

Thanks in advance, - Satya

1
Are you capturing the completionHandler in handleEventsForBackgroundURLSession in the app delegate? And, in URLSessionDidFinishEventsForBackgroundURLSession in your NSURLSessionDelegate, after initiating the other background request(s), did you call the saved completionHandler?Rob
I'm not sure abt this... I am sending the same message for all download objects, so I feel that this is automatically done...Satyaranjan
please see my comment for Leonardo's reply for the above thingSatyaranjan
You show us your code for saving the completion handler, great, but where do you call that completion handler? Your error suggests that you're not calling the completion handler quickly enough, which means either that you're taking too much time before doing it (I think you have something like 30 sec, so I find that surprising) or you're somehow neglecting to call it at all.Rob

1 Answers

0
votes

You have limited time when on background, so chances are that you're taking too long to process the file. If you don't call the completion handler fast enough, the system will crash your app.

Or you may have made a mistake and you are not calling the completion handler at all on the scenario where NSURLSessionDownloadTask initiates in background.