# URLSessionConfiguration.background(withIdentifier:) implementation

**URL:** <https://forums.swift.org/t/urlsessionconfiguration-background-withidentifier-implementation/26024>\
**Category:** Core Libraries\
**Tags:** foundation\
**Created:** [June 18, 2019, 3:44pm UTC](https://forums.swift.org/t/urlsessionconfiguration-background-withidentifier-implementation/26024 "2019-06-18T15:44:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthikkeyan.balan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/karthikkeyan.balan/32/21168_2.png) [@karthikkeyan.balan](https://forums.swift.org/u/karthikkeyan.balan)\
**Post date:** [June 18, 2019, 3:44pm UTC](https://forums.swift.org/t/urlsessionconfiguration-background-withidentifier-implementation/26024/1 "2019-06-18T15:44:25Z")

</div>

Hi Guys,

I am trying to understand how tasks added into Sessions with the background configuration, in order to implement `URLSessionConfiguration.background(withIdentifier:)` method.

As per Apple's documentation,

> A session configured with this object hands control of the transfers over to the system, which handles the transfers in a separate process. In iOS, this configuration makes it possible for transfers to continue even when the app itself is suspended or terminated.

If the system is taking control over the transfer, then a new session with the same background-identifier should be able to fetch any existing background tasks. I ran this small piece of code to confirm and it did work as I was expecting

```swift
let urlString = "https://developer.apple.com/assets/elements/icons/brandmark/apple-developer-brandmark.svg"
let identifier = "com.swiftfoundation.test_urlSessionConfigurationBackground"
let session = URLSession(configuration: URLSessionConfiguration.background(withIdentifier: identifier))
let task = session.dataTask(with: URL(string: urlString)!)
task.resume()
let taskIdentifier = task.taskIdentifier

DispatchQueue.global().async {
    let session2 = URLSession(configuration: URLSessionConfiguration.background(withIdentifier: identifier))
    session2.getAllTasks { (tasks) in
        let filter = tasks.filter { $0.taskIdentifier == taskIdentifier }
        if filter.first?.currentRequest?.url?.absoluteString == urlString {
            print("Found")
        } else {
            print("Not Found")
        }
    }
}

```

The above code prints `"Found"` all the time.

Here are my questions,

1. Is this the same expected behavior for apple/swift-corelibs-foundation project?
2. If so, as I don't know much about creating a system process, can I get some guidance from this good dev-community to implement.  
a. How to transfer a URLSession or easy\_handle or multi\_handle over to system  
b. How to retrieve them back later.

This could be a good learning experience for me. Please and thank you in advance.
