Skip to content

Commit

Permalink
Added the option to use a foreground URLSession for the WebDAVProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
phil1995 committed Dec 8, 2020
1 parent 639117c commit 403deac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Sources/CryptomatorCloudAccess/WebDAV/WebDAVClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class WebDAVClient {
self.webDAVSession = session
}

public convenience init(credential: WebDAVCredential, sharedContainerIdentifier: String) {
public convenience init(credential: WebDAVCredential, sharedContainerIdentifier: String, useBackgroundSession: Bool) {
let urlSessionDelegate = WebDAVClientURLSessionDelegate(credential: credential)
self.init(credential: credential, session: WebDAVSession(sharedContainerIdentifier: sharedContainerIdentifier, delegate: urlSessionDelegate))
self.init(credential: credential, session: WebDAVSession(sharedContainerIdentifier: sharedContainerIdentifier, delegate: urlSessionDelegate, useBackgroundSession: useBackgroundSession))
}

// MARK: - HTTP Methods for WebDAV
Expand Down
13 changes: 10 additions & 3 deletions Sources/CryptomatorCloudAccess/WebDAV/WebDAVSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,16 @@ class WebDAVSession {
self.delegate = delegate
}

convenience init(sharedContainerIdentifier: String, delegate: WebDAVClientURLSessionDelegate) {
let configuration = URLSessionConfiguration.background(withIdentifier: "CloudAccessWebDAVSession_\(delegate.credential.identifier)")
configuration.sharedContainerIdentifier = sharedContainerIdentifier
convenience init(sharedContainerIdentifier: String, delegate: WebDAVClientURLSessionDelegate, useBackgroundSession: Bool) {
let configuration: URLSessionConfiguration
if useBackgroundSession {
// Additionally use the bundleID to prevent the same background URLSession identifier for multiple targets (for example Main App and Extension).
let bundleId = Bundle.main.bundleIdentifier ?? ""
configuration = URLSessionConfiguration.background(withIdentifier: "CloudAccessWebDAVSession_\(delegate.credential.identifier)_\(bundleId)")
configuration.sharedContainerIdentifier = sharedContainerIdentifier
} else {
configuration = URLSessionConfiguration.default
}
configuration.httpCookieStorage = HTTPCookieStorage()
let session = URLSession(configuration: configuration, delegate: delegate, delegateQueue: nil)
self.init(urlSession: session, delegate: delegate)
Expand Down

0 comments on commit 403deac

Please sign in to comment.