I'm working on an app where a user can 'record' a route which he/she is driving with his car. Every 1 sec we save a coordinate to a list and every 30 seconds we also save the coordinate to the database for this, but this only works when the app is active/on the foreground.
So the only issue we, and foremost the users, have is the fact that the app stops the record function when the app went inactive/on the background. I want to implement and enable this feature, but even after a lot of google-ing and research I did not manage to find a solution.
In the app I'm using Mapbox Maps SDK and Mapbox Navigation SDK. The addCoor()-function gives me the coordinate of the user by self.mapView.userLocation!.coordinate and manages that every coordinate is added to an Array in the viewcontroller and that every 30 seconds a HTTP POST is made to add the coordinate to the database.
So the point is that I want to keep addCoor() running, also when the users send the app to the background, until the user stops the tracking himself/herself, by pressing the stop button in-app, or when a max of waypoint is reached. At that point I want to call stopTracking() so the route will be finalised.
As an extra I also want make it possible that when the app goes in the background a notifications pops up which allows the user to open the app and immediately calls stopTracking() when they click the notification.
Anyone who has any experience with background tasks in swift. All help is welcome!