ios - watchOS3 handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) on device be called -
i found method called on simulator, on real watch device, never called. both apple's simple code , test.
i want know 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>) { task : wkrefreshbackgroundtask in backgroundtasks { if task wksnapshotrefreshbackgroundtask { textlbl.settext("hahahah"); task.settaskcompleted() } } } }
i managed find workaround pointing scheduledcompletion attribute "real" function rather closure e.g.
wkextension.shared().schedulebackgroundrefresh( withpreferreddate: nextrefreshtime!, userinfo: nil, scheduledcompletion: self.backgroundrefreshrunning) ... private func backgroundrefreshrunning(error: error?) { if (error != nil) { print("error running background task: \(error.debugdescription)") } }
that seems work fine!
my guess there bug in swift 3 compiler. used use inline closure scheduledcompletion value, worked fine until updated code swift 2.3 swift 3
Comments
Post a Comment