I am working with Xamarin.iOS and implementing a Downloadmanager.
I have found a tutorial on how to implement a DownloadManager in swift, lead by that tutorial I have transcribed the logic written in swift into C#. The DownloadManager works and queues Operations and executes them. The only issue I am facing is the transition of the App to suspended mode. The behavior of the queue is not so deterministic. Sometimes all queued operations are executed and sometimes the app stops the execution.
Use Case 1: I start the file sync and lock the iPad. Most of the time the queued operations are executed. But sometimes when I unlock the iPad the Application is send to the background and I have to double tap the home button to return to the Application, in this case the file sync has stopped somehow in the middle of execution.
Use Case 2: I start the file sync and send the app to the background. The same behavior like in the previous use case. Sometimes all operations are executed and sometimes the operations stops.
Use Case 3: The customer starts the sync and leaves the iPad unattended after some time he comes back and the Sync is not finished and the Application is in the background. In average about 70% of the sync is done.
For the implementation I have used a "NSOperationQueue" that has "DownloadOperation" as elements. The "DownloadOperation" are just a wrapped of the NSOperation object with the execution set to "Asynchronous".
Possible Questions
- I am not sure what happens to the "NSOperationQueue" when the Application changes states?
- Is the usage of the "NSOperationQueue" the "right" way to go with the implementation of a DownloadManager?
- Are there any common tips for the optimisation of the execution of the "NSOperationQueue" and/or the "NSOperation"
Looking forward to the discussion.
P.S. I have enabled "Background Modes" and "Background Fetch"