In my project the user can choose to save their coordinates to firebase json. I currently using tab bars as my main navigation. What is the best approach to continue to save their gps even when they are navigating to other view controllers in the app.
Asked
Active
Viewed 42 times
0
-
You may use a background thread to regularly update your database. See [How to use background thread in swift?](http://stackoverflow.com/questions/24056205/how-to-use-background-thread-in-swift) – andih Jul 27 '16 at 08:19
-
Is your Project an IOS Project? – andih Jul 27 '16 at 08:22
1 Answers
0
You could create a locationManager singleton, it can handle all your location methods instead of placing it in a viewController ;)
And if you want to save your user position locally, you can use NSUserDefault, or CoreData, or save it in your locationManager singleton if it's just for the session.

Damien
- 3,322
- 3
- 19
- 29
-
How does a locationManager solve the problem of continuously saving the location data? A locationManager is first and foremost a way how you organize your code / functionality. – andih Jul 27 '16 at 09:00
-
I just think it's a good place to save data linked to location for the session and get them from anywhere in the app. Am I wrong ? – Damien Jul 27 '16 at 10:24
-
From the app design that makes sense. But just a singleton does not solve the problem. If you add that you start a background thread that periodically saves the location to your locationManager then it would be a solution. – andih Jul 27 '16 at 10:32
-
Or you can just save your location in locationManager every time your locationManager userLocationUpdate method triggers. – Damien Jul 27 '16 at 10:35
-
You mean your locationManager implements the `CLLocationManagerDelegate`? Yes. – andih Jul 27 '16 at 10:59