@@ -17,13 +17,43 @@ public struct NKSession: Sendable {
1717 public let httpMaximumConnectionsPerHostInDownload : Int
1818 public let httpMaximumConnectionsPerHostInUpload : Int
1919 public let dav : String = " remote.php/dav "
20+ public var sharedCookieStorage = " "
2021 public let sessionData : Alamofire . Session
2122 public let sessionDataNoCache : Alamofire . Session
2223 public let sessionDownloadBackground : URLSession
23- public let sessionDownloadBackgroundExt : URLSession
24+ public let backgroundSessionDelegate : URLSessionDelegate ?
2425 public let sessionUploadBackground : URLSession
2526 public let sessionUploadBackgroundWWan : URLSession
26- public let sessionUploadBackgroundExt : URLSession
27+
28+ public lazy var sessionDownloadBackgroundExt : URLSession = {
29+ let config = URLSessionConfiguration . background ( withIdentifier: NKCommon ( ) . identifierSessionDownloadBackgroundExt)
30+ config. sharedContainerIdentifier = groupIdentifier
31+ config. sessionSendsLaunchEvents = true
32+ config. isDiscretionary = false
33+ config. allowsCellularAccess = true
34+ config. requestCachePolicy = . useProtocolCachePolicy
35+ config. httpMaximumConnectionsPerHost = httpMaximumConnectionsPerHostInDownload
36+ config. httpCookieStorage = HTTPCookieStorage . sharedCookieStorage ( forGroupContainerIdentifier: sharedCookieStorage)
37+ #if os(iOS) || targetEnvironment(macCatalyst)
38+ config. multipathServiceType = . handover
39+ #endif
40+ return URLSession ( configuration: config, delegate: backgroundSessionDelegate, delegateQueue: . main)
41+ } ( )
42+
43+ public lazy var sessionUploadBackgroundExt : URLSession = {
44+ let config = URLSessionConfiguration . background ( withIdentifier: NKCommon ( ) . identifierSessionUploadBackgroundExt)
45+ config. sharedContainerIdentifier = groupIdentifier
46+ config. sessionSendsLaunchEvents = true
47+ config. isDiscretionary = false
48+ config. allowsCellularAccess = true
49+ config. requestCachePolicy = . useProtocolCachePolicy
50+ config. httpMaximumConnectionsPerHost = httpMaximumConnectionsPerHostInUpload
51+ config. httpCookieStorage = HTTPCookieStorage . sharedCookieStorage ( forGroupContainerIdentifier: sharedCookieStorage)
52+ #if os(iOS) || targetEnvironment(macCatalyst)
53+ config. multipathServiceType = . handover
54+ #endif
55+ return URLSession ( configuration: config, delegate: backgroundSessionDelegate, delegateQueue: . main)
56+ } ( )
2757
2858 init ( nkCommonInstance: NKCommon ,
2959 urlBase: String ,
@@ -46,10 +76,10 @@ public struct NKSession: Sendable {
4676 self . httpMaximumConnectionsPerHost = httpMaximumConnectionsPerHost
4777 self . httpMaximumConnectionsPerHostInDownload = httpMaximumConnectionsPerHostInDownload
4878 self . httpMaximumConnectionsPerHostInUpload = httpMaximumConnectionsPerHostInUpload
79+ self . backgroundSessionDelegate = NKBackground ( nkCommonInstance: nkCommonInstance)
4980
50- let backgroundSessionDelegate = NKBackground ( nkCommonInstance: nkCommonInstance)
5181 // Strange but works ?!?!
52- let sharedCookieStorage = user + " @ " + urlBase
82+ sharedCookieStorage = user + " @ " + urlBase
5383
5484 // SessionData Alamofire
5585 let configurationSessionData = URLSessionConfiguration . af. default
@@ -100,26 +130,6 @@ public struct NKSession: Sendable {
100130 configurationDownloadBackground. httpCookieStorage = HTTPCookieStorage . sharedCookieStorage ( forGroupContainerIdentifier: sharedCookieStorage)
101131 sessionDownloadBackground = URLSession ( configuration: configurationDownloadBackground, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue . main)
102132
103- // Session Download Background Extension
104- let configurationDownloadBackgroundExt = URLSessionConfiguration . background ( withIdentifier: NKCommon ( ) . identifierSessionDownloadBackgroundExt + UUID( ) . uuidString)
105- configurationDownloadBackgroundExt. allowsCellularAccess = true
106-
107- if #available( macOS 11 , * ) {
108- configurationDownloadBackgroundExt. sessionSendsLaunchEvents = true
109- }
110-
111- configurationDownloadBackgroundExt. isDiscretionary = false
112- configurationDownloadBackgroundExt. httpMaximumConnectionsPerHost = self . httpMaximumConnectionsPerHostInDownload
113- configurationDownloadBackgroundExt. requestCachePolicy = . useProtocolCachePolicy
114- configurationDownloadBackgroundExt. sharedContainerIdentifier = groupIdentifier
115-
116- #if os(iOS) || targetEnvironment(macCatalyst)
117- configurationDownloadBackgroundExt. multipathServiceType = . handover
118- #endif
119-
120- configurationDownloadBackgroundExt. httpCookieStorage = HTTPCookieStorage . sharedCookieStorage ( forGroupContainerIdentifier: sharedCookieStorage)
121- sessionDownloadBackgroundExt = URLSession ( configuration: configurationDownloadBackgroundExt, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue . main)
122-
123133 // Session Upload Background
124134 let configurationUploadBackground = URLSessionConfiguration . background ( withIdentifier: NKCommon ( ) . getSessionConfigurationIdentifier ( NKCommon ( ) . identifierSessionUploadBackground, account: account) )
125135 configurationUploadBackground. allowsCellularAccess = true
@@ -152,25 +162,5 @@ public struct NKSession: Sendable {
152162 configurationUploadBackgroundWWan. requestCachePolicy = . useProtocolCachePolicy
153163 configurationUploadBackgroundWWan. httpCookieStorage = HTTPCookieStorage . sharedCookieStorage ( forGroupContainerIdentifier: sharedCookieStorage)
154164 sessionUploadBackgroundWWan = URLSession ( configuration: configurationUploadBackgroundWWan, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue . main)
155-
156- // Session Upload Background Extension
157- let configurationUploadBackgroundExt = URLSessionConfiguration . background ( withIdentifier: NKCommon ( ) . identifierSessionUploadBackgroundExt + UUID( ) . uuidString)
158- configurationUploadBackgroundExt. allowsCellularAccess = true
159-
160- if #available( macOS 11 , * ) {
161- configurationUploadBackgroundExt. sessionSendsLaunchEvents = true
162- }
163-
164- configurationUploadBackgroundExt. isDiscretionary = false
165- configurationUploadBackgroundExt. httpMaximumConnectionsPerHost = self . httpMaximumConnectionsPerHostInUpload
166- configurationUploadBackgroundExt. requestCachePolicy = . useProtocolCachePolicy
167- configurationUploadBackgroundExt. sharedContainerIdentifier = groupIdentifier
168-
169- #if os(iOS) || targetEnvironment(macCatalyst)
170- configurationUploadBackgroundExt. multipathServiceType = . handover
171- #endif
172-
173- configurationUploadBackgroundExt. httpCookieStorage = HTTPCookieStorage . sharedCookieStorage ( forGroupContainerIdentifier: sharedCookieStorage)
174- sessionUploadBackgroundExt = URLSession ( configuration: configurationUploadBackgroundExt, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue . main)
175165 }
176166}
0 commit comments