Fix profile upate task

This commit is contained in:
世界
2023-09-22 18:00:19 +08:00
parent 3374f8e727
commit 58bc9baa05
5 changed files with 33 additions and 21 deletions
@@ -5,16 +5,21 @@ import Library
#if os(iOS) || os(tvOS)
public class UIProfileUpdateTask: BGAppRefreshTask {
private static let taskSchedulerPermittedIdentifier = "\(FilePath.packageName).update_profiles"
private static var registered = false
public static func configure() async throws {
let success = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskSchedulerPermittedIdentifier, using: nil) { task in
NSLog("profile update task started")
Task {
await getAndupdateProfiles(task)
if !registered {
let success = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskSchedulerPermittedIdentifier, using: nil) { task in
NSLog("profile update task started")
Task {
await getAndupdateProfiles(task)
}
}
}
if !success {
throw NSError(domain: "register failed", code: 0)
if !success {
throw NSError(domain: "register failed", code: 0)
}
registered = true
}
BGTaskScheduler.shared.cancelAllTaskRequests()
let profiles = try await ProfileManager.listAutoUpdateEnabled()