Skip to content

Commit fa86aaa

Browse files
committed
Add missing attributes to NSURLSession.Configuration
1 parent 4bf1bfd commit fa86aaa

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

Foundation/NSURLSession.swift

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,8 @@ public class NSURLSessionConfiguration : NSObject, NSCopying {
14891489
super.init()
14901490
}
14911491

1492-
private init(requestCachePolicy: NSURLRequestCachePolicy,
1492+
private init(identifier: String?,
1493+
requestCachePolicy: NSURLRequestCachePolicy,
14931494
timeoutIntervalForRequest: NSTimeInterval,
14941495
timeoutIntervalForResource: NSTimeInterval,
14951496
networkServiceType: NSURLRequestNetworkServiceType,
@@ -1503,8 +1504,11 @@ public class NSURLSessionConfiguration : NSObject, NSCopying {
15031504
HTTPMaximumConnectionsPerHost: Int,
15041505
HTTPCookieStorage: NSHTTPCookieStorage?,
15051506
URLCredentialStorage: NSURLCredentialStorage?,
1506-
URLCache: NSURLCache?)
1507+
URLCache: NSURLCache?,
1508+
shouldUseExtendedBackgroundIdleMode: Bool,
1509+
protocolClasses: [AnyClass]?)
15071510
{
1511+
self.identifier = identifier
15081512
self.requestCachePolicy = requestCachePolicy
15091513
self.timeoutIntervalForRequest = timeoutIntervalForRequest
15101514
self.timeoutIntervalForResource = timeoutIntervalForResource
@@ -1520,11 +1524,17 @@ public class NSURLSessionConfiguration : NSObject, NSCopying {
15201524
self.HTTPCookieStorage = HTTPCookieStorage
15211525
self.URLCredentialStorage = URLCredentialStorage
15221526
self.URLCache = URLCache
1523-
self.shouldUseExtendedBackgroundIdleMode = false
1527+
self.shouldUseExtendedBackgroundIdleMode = shouldUseExtendedBackgroundIdleMode
1528+
self.protocolClasses = protocolClasses
15241529
}
15251530

15261531
public override func copy() -> AnyObject {
1532+
return copyWithZone(nil)
1533+
}
1534+
1535+
public func copyWithZone(zone: NSZone) -> AnyObject {
15271536
return NSURLSessionConfiguration(
1537+
identifier: identifier,
15281538
requestCachePolicy: requestCachePolicy,
15291539
timeoutIntervalForRequest: timeoutIntervalForRequest,
15301540
timeoutIntervalForResource: timeoutIntervalForResource,
@@ -1539,11 +1549,9 @@ public class NSURLSessionConfiguration : NSObject, NSCopying {
15391549
HTTPMaximumConnectionsPerHost: HTTPMaximumConnectionsPerHost,
15401550
HTTPCookieStorage: HTTPCookieStorage,
15411551
URLCredentialStorage: URLCredentialStorage,
1542-
URLCache: URLCache)
1543-
}
1544-
1545-
public func copyWithZone(zone: NSZone) -> AnyObject {
1546-
NSUnimplemented()
1552+
URLCache: URLCache,
1553+
shouldUseExtendedBackgroundIdleMode: shouldUseExtendedBackgroundIdleMode,
1554+
protocolClasses: protocolClasses)
15471555
}
15481556

15491557
public class func defaultSessionConfiguration() -> NSURLSessionConfiguration {
@@ -1553,7 +1561,7 @@ public class NSURLSessionConfiguration : NSObject, NSCopying {
15531561
public class func backgroundSessionConfigurationWithIdentifier(identifier: String) -> NSURLSessionConfiguration { NSUnimplemented() }
15541562

15551563
/* identifier for the background session configuration */
1556-
public var identifier: String? { NSUnimplemented() }
1564+
public var identifier: String?
15571565

15581566
/* default cache policy for requests */
15591567
public var requestCachePolicy: NSURLRequestCachePolicy
@@ -1641,6 +1649,9 @@ public class NSURLSessionConfiguration : NSObject, NSCopying {
16411649

16421650
internal extension NSURLSession {
16431651
struct Configuration {
1652+
/// identifier for the background session configuration
1653+
let identifier: String?
1654+
16441655
/// default cache policy for requests
16451656
let requestCachePolicy: NSURLRequestCachePolicy
16461657

@@ -1653,6 +1664,12 @@ internal extension NSURLSession {
16531664
/// type of service for requests.
16541665
let networkServiceType: NSURLRequestNetworkServiceType
16551666

1667+
/// allow request to route over cellular.
1668+
let allowsCellularAccess: Bool
1669+
1670+
/// allows background tasks to be scheduled at the discretion of the system for optimal performance.
1671+
let discretionary: Bool
1672+
16561673
/// The proxy dictionary, as described by <CFNetwork/CFHTTPStream.h>
16571674
let connectionProxyDictionary: [NSObject : AnyObject]?
16581675

@@ -1671,20 +1688,42 @@ internal extension NSURLSession {
16711688
let HTTPAdditionalHeaders: [String : String]?
16721689
/// The maximum number of simultanous persistent connections per host
16731690
let HTTPMaximumConnectionsPerHost: Int
1691+
1692+
/// The cookie storage object to use, or nil to indicate that no cookies should be handled
1693+
let HTTPCookieStorage: NSHTTPCookieStorage?
1694+
1695+
/// The credential storage object, or nil to indicate that no credential storage is to be used
1696+
let URLCredentialStorage: NSURLCredentialStorage?
1697+
1698+
/// The URL resource cache, or nil to indicate that no caching is to be performed
1699+
let URLCache: NSURLCache?
1700+
1701+
/// Enable extended background idle mode for any tcp sockets created.
1702+
let shouldUseExtendedBackgroundIdleMode: Bool
1703+
1704+
let protocolClasses: [AnyClass]?
16741705
}
16751706
}
16761707
private extension NSURLSession.Configuration {
16771708
init(URLSessionConfiguration config: NSURLSessionConfiguration) {
1709+
identifier = config.identifier
16781710
requestCachePolicy = config.requestCachePolicy
16791711
timeoutIntervalForRequest = config.timeoutIntervalForRequest
16801712
timeoutIntervalForResource = config.timeoutIntervalForResource
16811713
networkServiceType = config.networkServiceType
1714+
allowsCellularAccess = config.allowsCellularAccess
1715+
discretionary = config.discretionary
16821716
connectionProxyDictionary = config.connectionProxyDictionary
16831717
HTTPShouldUsePipelining = config.HTTPShouldUsePipelining
16841718
HTTPShouldSetCookies = config.HTTPShouldSetCookies
16851719
HTTPCookieAcceptPolicy = config.HTTPCookieAcceptPolicy
16861720
HTTPAdditionalHeaders = config.HTTPAdditionalHeaders.map { convertToStringString(dictionary: $0) }
16871721
HTTPMaximumConnectionsPerHost = config.HTTPMaximumConnectionsPerHost
1722+
HTTPCookieStorage = config.HTTPCookieStorage
1723+
URLCredentialStorage = config.URLCredentialStorage
1724+
URLCache = config.URLCache
1725+
shouldUseExtendedBackgroundIdleMode = config.shouldUseExtendedBackgroundIdleMode
1726+
protocolClasses = config.protocolClasses
16881727
}
16891728
}
16901729

0 commit comments

Comments
 (0)