I'm developing a watchOS app that executes regularly in the background using background refresh tasks. A while ago I put in a call to update the watch's complication at each background refresh. This quickly burned through all of the complication updates and, I believe, the background budget for the app. I assumed it would reset at the beginning of the next day, but this doesn't seem to be the case. Since then, even though I've removed the complication refresh code altogether the app does not consistently execute background refreshes. I've deleted the app and reinstalled it and waited about a week but it only executes these refreshes regularly when run through Xcode (on the device), not when run independently. Any ideas?
Update:
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for backgroundTask in backgroundTasks {
switch backgroundTask {
case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask:
connectivityTask.setTaskCompleted()
case let refreshTask as WKApplicationRefreshBackgroundTask:
MainInterfaceController.scheduleTask()
refreshTask.setTaskCompleted()
case let snapshotTask as WKSnapshotRefreshBackgroundTask:
snapshotTask.setTaskCompleted()
default:
backgroundTask.setTaskCompleted()
}
}
DataProcessor.sharedInstance.dataProcessing()
public static func scheduleTask() {
let fireDate = Date(timeIntervalSinceNow: 10.0)
WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: fireDate, userInfo: nil) { (error) in
if (error == nil) {
print("Background task scheduled")
}
}
}
And a task is scheduled when the application deactivates, kicking off the chain. This code was all working previously, which is the confusing part.