I'm having trouble with my WatchKit app crashing in WatchOS 5. This is happening in the background when my system calls my app to let me update the complication.
The code snippet here is called in the background when I get a WKApplicationBackgroundRefreshTask:
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for task in backgroundTasks {
switch task {
case let backgroundTask as WKApplicationRefreshBackgroundTask:
HealthController().updateComplicationData {
self.updateComplications()
if #available(watchOSApplicationExtension 4.0, *) {
backgroundTask.setTaskCompletedWithSnapshot(false)
} else { task.setTaskCompleted()}
}
The issue is, the crash I get basically says:
[WKRefreshBackgroundTask dealloc]
So I'm aware, this could be happening if the HealthController().updateComplicationData() function takes too long to return. But the crash doesn't imply the app is being killed for cpu time issues. It seems that the actual backgroundTask variable is getting deallocated so that when the backgroundTask.setTaskCompletedWithSnapshot(false) call happens I pass a deallocated object.
Any suggestions?
HealthController().updateComplicationData creates?Thanks for your help!
I have finally solved this incase anyone else experiences it! Basically, I had an odd pathline of code in the background refresh where occasionally the finishedBackgroundUpdate handler wasnt called. Because of this WatchKit was killing the app. All solved now though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With