I am using background task to run the timer in the background to update the user\'s location. It\'s declared as:
UIBackgroundTaskIdentifier bgTask;
I think there is a bug working with xcode 11.2 and the swiftUI framework because I always get the
"Can't end BackgroundTask: no background task exists with identifier..."
message even when my app is not working with background tasks! The good news is that this only stops my app when executing from xcode; use the 'continue program execution' button and the app will be running again.
In Xcode, switch to the breakpoint navigator (View > Navigators > Show Breakpoint Navigator) then push the + button in the bottom left and select Add Symbolic Breakpoint and enter “UIApplicationEndBackgroundTaskError” as the symbol.
Regarding the “Can’t end BackgroundTask: no background task exists with identifier ...” message, as others have said, this can be a red herring, unrelated to what you’re doing.
Regarding your goal of trying to periodically retrieve the user’s location, rather than trying to keep your app running in the background with a timer, you should instead avail yourself of various services for updating the user location in the background, such as the visits location service or the significant change location service. With these services, the OS can wake your app when there is a change in the user’s location.