mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-12-02 13:04:14 +01:00
feat: Handle iOS background downloads
This commit is contained in:
1 parent
b02dd18e0b
commit
35631fb211
2 files changed
+21
-1
No files matched your search
@@ -15,9 +15,10 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
||||
static private let downloadsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||
|
||||
private lazy var session: URLSession = {
|
||||
let config = URLSessionConfiguration.background(withIdentifier: "AbsDownloader")
|
||||
let queue = OperationQueue()
|
||||
queue.maxConcurrentOperationCount = 5
|
||||
return URLSession(configuration: .default, delegate: self, delegateQueue: queue)
|
||||
return URLSession(configuration: config, delegate: self, delegateQueue: queue)
|
||||
}()
|
||||
private let progressStatusQueue = DispatchQueue(label: "progress-status-queue", attributes: .concurrent)
|
||||
private var downloadItemProgress = [String: DownloadItem]()
|
||||
@@ -78,6 +79,18 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
// Called when downloads are complete on the background thread
|
||||
public func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
|
||||
DispatchQueue.main.async {
|
||||
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate,
|
||||
let backgroundCompletionHandler =
|
||||
appDelegate.backgroundCompletionHandler else {
|
||||
return
|
||||
}
|
||||
backgroundCompletionHandler()
|
||||
}
|
||||
}
|
||||
|
||||
private func handleDownloadTaskUpdate(downloadTask: URLSessionTask, progressHandler: DownloadProgressHandler) {
|
||||
do {
|
||||
guard let downloadItemPartId = downloadTask.taskDescription else { throw LibraryItemDownloadError.noTaskDescription }
|
||||
|
||||
Reference in new issue
Block a user