Group Group Group Group Group Group Group Group Group

Networking with URLSession · Background Sessions in Action |

This is a companion discussion topic for the original entry at

Hi Brian, Can you help with something? If you pause and resume a download more than once, it frezees when you try to resume. I didn’t notice before because the downloads of halftunes are superfast in reason of the size of files. But i used the halftunes approach to my own project that download a podcast episodes and i having the trouble. Apparently after the second time you pause the download, the resume data produced can’t restart the download. Can you help me to solve this issue? Thanks!

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

This was discussed in another topic.

Hello Brian, there is very little documentation or sample code about uploading in the background and handling the callback after the server returns a response for the upload when the app is terminated by the user. All the examples that are out there are for downloading in the background, even in the official documentation. Could you please help in some code sample for the same.

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

I don’t believe we covered background uploading. Try following the same procedure for background downloading, but instead, use an upload task. Give it a shot and see what you find.

I followed your background downloading tutorial ( and converted it to background uploading. But somehow it is not working for me, when i put app in background. When I debug using Xcode, am getting " Could not load IOSurface for time string. Rendering locally instead." this message and it stops uploading but when i bring the app back in foreground it start uploading.

I am expecting my app to continue uploading files while it is in background as well as when the user closes the app. Could you please help? Thanks a lot!


@nareshkumowiz20 Do you still have issues with this?

Yes, but right now we are not focusing on it, coz it already taken our too much time. But if you have the answer then it will great to know.

Your best bet is to reach out on the Apple developer forums to see what’s happening.

In the handle events method in AppDelegate, I noticed that you are creating a new Instance of DownloadService instead of using the instance that is available in SearchViewController.

  1. DownloadService instance created in handle events method in AppDelegate is local to the method. Does it get deallocated after the method returns?

  2. What is the difference between the instance of DownloadService in SearchViewController and AppDelegate? I modified the Appdelgate method to look like below. Do you think it will have issues?

      func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
        backgroundSessionCompletionHandler = completionHandler
        let searchViewController = SearchViewController()
        let sessionConfiguration = URLSessionConfiguration.background(withIdentifier: identifier)
        let downloadSession = URLSession(configuration: sessionConfiguration, delegate: searchViewController, delegateQueue: nil)
        searchViewController.downloadService.downloadsSession = downloadSession

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]