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:
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!
Post
Replies
Boosts
Views
Activity
Greetings,
My code was working fine on a project utilizing the USGS API. I can still gather the data fine via my REST client so I know the data stream has not changed. Somewhere after updating to Xcode 12, I now get this error (yet I get a 200 response from the server) in my iOS app. I get the weird error above in the console followed by a lot of blank lines then this at the bottom of the debug console:
2020-10-17 11:56:48.320587-0400 RiversUp[21491:12725094] Fatal error: Can't remove first element from an empty collection: file Swift/RangeReplaceableCollection.swift, line 624
After several seconds my app has crashed and this happens on both the simulator and on the device in debug.
I am currently running Xcode 12.0.1 and building for a minimum of 14.0 on iOS. I have an independent watch app as well that uses the same API calls and is getting the same errors when building for a minimum of watchOS 7.0.
Any help would be greatly appreciated as this is a total app killer.
Thanks,
Mark