WIP - a lot of uncommitted work

This commit is contained in:
Trey t
2022-01-15 12:03:31 -06:00
parent 80690e4a8c
commit 64dd1855ac
31 changed files with 1024 additions and 154 deletions

40
Shared/BGTask.swift Normal file
View File

@@ -0,0 +1,40 @@
//
// BGTask.swift
// Feels (iOS)
//
// Created by Trey Tartt on 1/12/22.
//
import Foundation
import BackgroundTasks
class BGTask {
static let updateDBMissingID = "com.88oak.Feels.dbUpdateMissing"
class func runFillInMissingDatesTask(task: BGProcessingTask) {
BGTask.scheduleBackgroundProcessing()
task.expirationHandler = {
task.setTaskCompleted(success: false)
}
PersistenceController.shared.fillInMissingDates()
task.setTaskCompleted(success: true)
}
class func scheduleBackgroundProcessing() {
let request = BGProcessingTaskRequest(identifier: BGTask.updateDBMissingID)
request.requiresNetworkConnectivity = false
request.requiresExternalPower = false
var runDate = Calendar.current.date(byAdding: .day, value: 1, to: Date())
runDate = Calendar.current.date(bySettingHour: 0, minute: 1, second: 0, of: runDate!)
request.earliestBeginDate = runDate
do {
try BGTaskScheduler.shared.submit(request)
} catch {
print("Could not schedule image fetch: (error)")
}
}
}