Skip to content

Commit 0d23a4e

Browse files
committed
URLSessionConfiguration.background(withIdentifier) method implemented
1 parent 6c871ea commit 0d23a4e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Foundation/URLSession/URLSessionConfiguration.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,17 @@ open class URLSessionConfiguration : NSObject, NSCopying {
156156
return ephemeralConfiguration
157157
}
158158

159-
open class func background(withIdentifier identifier: String) -> URLSessionConfiguration { NSUnimplemented() }
159+
open class func background(withIdentifier identifier: String) -> URLSessionConfiguration {
160+
if identifier.isEmpty {
161+
// As per document: The unique identifier for the configuration object. This parameter must not be nil or an empty string.
162+
// But it is unclear what happens when it is empty, the existing Foundation framework creates an instance anyway.
163+
// FIXME: Handle empty string properly
164+
}
165+
let backgroundConfiguration = URLSessionConfiguration.default.copy() as! URLSessionConfiguration
166+
backgroundConfiguration.identifier = identifier
167+
backgroundConfiguration.urlCache = nil
168+
return backgroundConfiguration
169+
}
160170

161171
/* identifier for the background session configuration */
162172
open var identifier: String?

0 commit comments

Comments
 (0)