I\'m working on a complication to get scheduled data from a web service. Every 20-30 minutes (or manually), I am scheduling a WKRefreshBackgroundTask to do this.
As
I got it working! I started out by looking a lot at the WWDC'16 videoes/notes, comparing them to the WatchBackgroundRefresh example from Apple. Then, while browsing the Apple Dev forums, I found this thread, with the same problem we encountered. There, a guy, "Daniel Fontes" posts his 'recipe' for getting it to work (note, not the accepted answer!), and that combined with the videos worked for me.
What I did to make the Apple example work:
var savedTask:WKRefreshBackgroundTask?
handle( backgroundTasks:)
function, save the WKURLSessionRefreshBackgroundTask
to the local variable self.savedTask = task
- do not task.setTaskCompleted() (!!) urlSession - didFinishDownloading:
, set the saved task to completed: self.savedTask?.setTaskCompleted()
after you've read the data received.Hope this can help!
ps. this works in the simnulator (xcode 8.3.3, watchOS 3.2)