0

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.

rharding
  • 551
  • 1
  • 3
  • 14
  • Please include the actual code causing the issue. Moreover, do you actually receive an error about having used up your background refresh budget or the refreshes just don't happen? – Dávid Pásztor Sep 12 '17 at 16:45
  • I don't have the specific code anymore but I was simply calling getCurrentTimelineEntry every time an Application Refresh Task was handled. I'm not getting a specific message saying that the budget has been used up but the background refreshes have inexplicably stopped – rharding Sep 12 '17 at 17:04
  • Then please include the code you're currently using for the background refreshes in the question. – Dávid Pásztor Sep 12 '17 at 20:01
  • I've added the code above – rharding Sep 12 '17 at 23:20
  • Have you found a fix for your problem? And could you somehow determine that your budget was used? I have an odd issue with my app, where everything will run for weeks in the simulator, but only half a day on the watch. I suspect I'm burning the budget too, but how to tell? – Jens Peter Oct 21 '17 at 07:54
  • @JensPeter I never found that I explicitly had run through the background budget but that was my belief. The other two people developing the app continued to have well functioning apps on their devices but mine has never really recovered – rharding Oct 23 '17 at 15:29
  • @JensPeter I recently changed my background code so that before processing data it send a push notification to the watch. I still receive these, showing that the background task is being handled and the chain of them continues, but the data processing never completes – rharding Oct 24 '17 at 16:01
  • @RossHarding Having same problem.. Any change you figured this out? – ZassX Jan 31 '18 at 15:14
  • @ZassX I limited data processing in the background to no more than 30 minutes of data and haven't had any problems since – rharding Jan 31 '18 at 18:35
  • @RossHarding the background refresh is working ok on my device, but other test users are not getting updates at that time interval. I have around 35minutes refresh interval, did some fixes with the new build so I hope it will stabilise soon and start working on their devices too. – ZassX Jan 31 '18 at 21:03
  • @ZassX I have a background refresh every 10 minutes but if it misses some then it will process up to 30 minutes of data. This seems to work quite well. I've found there are issues though for users who aren't on watchOS 4 or who have the original (not the series 1) watch – rharding Jan 31 '18 at 21:41
  • @RossHarding Thank you very much for info! – ZassX Feb 01 '18 at 08:34

0 Answers0