Skip to content

Commit

Permalink
Reenabled build on macOS. (#109)
Browse files Browse the repository at this point in the history
Certain APIs used were not available on macOS in general or the currently supported version per package manifest. I added necessary code switches to make the code at least build again.

Co-authored-by: Marino Faggiana <[email protected]>
  • Loading branch information
i2h3 and marinofaggiana authored Nov 25, 2024
1 parent e6e0a54 commit fcfc5c7
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions Sources/NextcloudKit/NKSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public class NKSession {
/// Session Alamofire
let configuration = URLSessionConfiguration.af.default
configuration.requestCachePolicy = requestCachePolicy
configuration.multipathServiceType = .handover

#if os(iOS) || targetEnvironment(macCatalyst)
configuration.multipathServiceType = .handover
#endif

configuration.httpCookieStorage = HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier: sharedCookieStorage)
sessionData = Alamofire.Session(configuration: configuration,
delegate: NextcloudKitSessionDelegate(nkCommonInstance: NextcloudKit.shared.nkCommonInstance),
Expand All @@ -61,29 +65,49 @@ public class NKSession {
/// Session Download Background
let configurationDownloadBackground = URLSessionConfiguration.background(withIdentifier: NKCommon().identifierSessionDownloadBackground)
configurationDownloadBackground.allowsCellularAccess = true
configurationDownloadBackground.sessionSendsLaunchEvents = true

if #available(macOS 11, *) {
configurationDownloadBackground.sessionSendsLaunchEvents = true
}

configurationDownloadBackground.isDiscretionary = false
configurationDownloadBackground.httpMaximumConnectionsPerHost = 5
configurationDownloadBackground.requestCachePolicy = requestCachePolicy
configurationDownloadBackground.multipathServiceType = .handover

#if os(iOS) || targetEnvironment(macCatalyst)
configurationDownloadBackground.multipathServiceType = .handover
#endif

configurationDownloadBackground.httpCookieStorage = HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier: sharedCookieStorage)
sessionDownloadBackground = URLSession(configuration: configurationDownloadBackground, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue.main)

/// Session Upload Background
let configurationUploadBackground = URLSessionConfiguration.background(withIdentifier: NKCommon().identifierSessionUploadBackground)
configurationUploadBackground.allowsCellularAccess = true
configurationUploadBackground.sessionSendsLaunchEvents = true

if #available(macOS 11, *) {
configurationUploadBackground.sessionSendsLaunchEvents = true
}

configurationUploadBackground.isDiscretionary = false
configurationUploadBackground.httpMaximumConnectionsPerHost = 5
configurationUploadBackground.requestCachePolicy = requestCachePolicy
configurationUploadBackground.multipathServiceType = .handover

#if os(iOS) || targetEnvironment(macCatalyst)
configurationUploadBackground.multipathServiceType = .handover
#endif

configurationUploadBackground.httpCookieStorage = HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier: sharedCookieStorage)
sessionUploadBackground = URLSession(configuration: configurationUploadBackground, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue.main)

/// Session Upload Background WWan
let configurationUploadBackgroundWWan = URLSessionConfiguration.background(withIdentifier: NKCommon().identifierSessionUploadBackgroundWWan)
configurationUploadBackgroundWWan.allowsCellularAccess = false
configurationUploadBackgroundWWan.sessionSendsLaunchEvents = true

if #available(macOS 11, *) {
configurationUploadBackgroundWWan.sessionSendsLaunchEvents = true
}

configurationUploadBackgroundWWan.isDiscretionary = false
configurationUploadBackgroundWWan.httpMaximumConnectionsPerHost = 5
configurationUploadBackgroundWWan.requestCachePolicy = requestCachePolicy
Expand All @@ -93,12 +117,20 @@ public class NKSession {
/// Session Upload Background Extension
let configurationUploadBackgroundExt = URLSessionConfiguration.background(withIdentifier: NKCommon().identifierSessionUploadBackgroundExt + UUID().uuidString)
configurationUploadBackgroundExt.allowsCellularAccess = true
configurationUploadBackgroundExt.sessionSendsLaunchEvents = true

if #available(macOS 11, *) {
configurationUploadBackgroundExt.sessionSendsLaunchEvents = true
}

configurationUploadBackgroundExt.isDiscretionary = false
configurationUploadBackgroundExt.httpMaximumConnectionsPerHost = 5
configurationUploadBackgroundExt.requestCachePolicy = requestCachePolicy
configurationUploadBackgroundExt.sharedContainerIdentifier = groupIdentifier
configurationUploadBackgroundExt.multipathServiceType = .handover

#if os(iOS) || targetEnvironment(macCatalyst)
configurationUploadBackgroundExt.multipathServiceType = .handover
#endif

Check warning on line 133 in Sources/NextcloudKit/NKSession.swift

View workflow job for this annotation

GitHub Actions / Lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
configurationUploadBackgroundExt.httpCookieStorage = HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier: sharedCookieStorage)
sessionUploadBackgroundExt = URLSession(configuration: configurationUploadBackgroundExt, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue.main)
}
Expand Down

0 comments on commit fcfc5c7

Please sign in to comment.