Skip to content

Commit 1ee9ac1

Browse files
Merge pull request #159 from nextcloud/dow-up
task.resume
2 parents 6ae1648 + 7e884c2 commit 1ee9ac1

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Sources/NextcloudKit/NextcloudKitBackground.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
2828
public func download(serverUrlFileName: Any,
2929
fileNameLocalPath: String,
3030
taskDescription: String? = nil,
31+
automaticResume: Bool = true,
3132
account: String) -> (URLSessionDownloadTask?, error: NKError) {
3233
var url: URL?
3334
let groupDefaults = UserDefaults(suiteName: NextcloudKit.shared.nkCommonInstance.groupIdentifier)
@@ -69,7 +70,10 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
6970

7071
let task = nkSession.sessionDownloadBackground.downloadTask(with: request)
7172
task.taskDescription = taskDescription
72-
task.resume()
73+
74+
if automaticResume {
75+
task.resume()
76+
}
7377

7478
return (task, .success)
7579
}
@@ -84,6 +88,7 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
8488
public func downloadAsync(serverUrlFileName: Any,
8589
fileNameLocalPath: String,
8690
taskDescription: String? = nil,
91+
automaticResume: Bool = true,
8792
account: String) async -> (
8893
downloadTask: URLSessionDownloadTask?,
8994
error: NKError
@@ -92,6 +97,7 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
9297
let (task, error) = download(serverUrlFileName: serverUrlFileName,
9398
fileNameLocalPath: fileNameLocalPath,
9499
taskDescription: taskDescription,
100+
automaticResume: automaticResume,
95101
account: account)
96102
continuation.resume(returning: (downloadTask: task, error: error))
97103
}
@@ -121,6 +127,7 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
121127
taskDescription: String? = nil,
122128
overwrite: Bool = false,
123129
account: String,
130+
automaticResume: Bool = true,
124131
sessionIdentifier: String) -> (URLSessionUploadTask?, error: NKError) {
125132
var url: URL?
126133
var uploadSession: URLSession?
@@ -182,7 +189,10 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
182189

183190
let task = uploadSession?.uploadTask(with: request, fromFile: URL(fileURLWithPath: fileNameLocalPath))
184191
task?.taskDescription = taskDescription
185-
task?.resume()
192+
193+
if automaticResume {
194+
task?.resume()
195+
}
186196

187197
return (task, .success)
188198
}
@@ -201,6 +211,7 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
201211
taskDescription: String? = nil,
202212
overwrite: Bool = false,
203213
account: String,
214+
automaticResume: Bool = true,
204215
sessionIdentifier: String) async -> (
205216
uploadTask: URLSessionUploadTask?,
206217
error: NKError
@@ -213,6 +224,7 @@ public final class NKBackground: NSObject, URLSessionTaskDelegate, URLSessionDel
213224
taskDescription: taskDescription,
214225
overwrite: overwrite,
215226
account: account,
227+
automaticResume: automaticResume,
216228
sessionIdentifier: sessionIdentifier)
217229
continuation.resume(returning: (uploadTask: task, error: error))
218230
}

0 commit comments

Comments
 (0)