I found this method be called on the simulator, but on the real watch device, it is never called. Both the apple's simple code and my test.
I want to know is my mistakes or Apple's.
My code -
class InterfaceController: WKInterfaceController, WKExtensionDelegate {
@IBOutlet var textLbl: WKInterfaceLabel!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
WKExtension.shared().delegate = self
// Configure interface objects here.
}
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for task : WKRefreshBackgroundTask in backgroundTasks {
if task is WKSnapshotRefreshBackgroundTask {
textLbl.setText("hahahah");
task.setTaskCompleted()
}
}
}
}
I managed to find a workaround by pointing the scheduledCompletion attribute to a "real" function rather than a closure e.g.
That now seems to work fine!
My guess is there is a bug in the Swift 3 compiler. I used to use an inline closure for the scheduledCompletion value, which worked fine until I updated my code from Swift 2.3 to Swift 3