I have a background task from the Apple Watch that saves some data to a server every 30 - 60 minutes. It was working flawlessly on watchOS6 but stopped working on watchOS7. Strangely if I launch from Xcode on my device it works flawlessly again until it loses connection with the debugger. No background activities work when launched via TestFlight. I am not using the WKURLSessionRefreshBackgroundTask because the data I send is very small and the entire auth process and save to the server only takes about 2 seconds. Below is a sample of the code I am using:
Thanks in advance!
Code Block func applicationWillResignActive() { print ("Should go to background now") beginUploadTask() } func applicationDidEnterBackground() { print ("App in background now") WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: Date(timeIntervalSinceNow: 120), userInfo: nil) { (error: Error?) in if let error = error { print("Error occured while scheduling background refresh: \(error.localizedDescription)") } else { print ("Background refeesh scheduled") } } } func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) { for task in backgroundTasks { switch task { case let backgroundTask as WKApplicationRefreshBackgroundTask: beginUploadTask() backgroundTask.setTaskCompletedWithSnapshot(false) WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: Date(timeIntervalSinceNow: 30 * 60), userInfo: nil) { (error: Error?) in if let error = error { print("Error occured while scheduling background refresh: \(error.localizedDescription)") } else { print ("Background refeesh scheduled") } }
Thanks in advance!