Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put common code for iPhone, CLLocationManager

If I have a tab bar app, and plan on using Core Location in different tabs, is there a good common place to put the code used to alloc/init the CLLocationManager, and get the updates once startUpdatingLocation is called? Or if it's going to be used in two different tabs, do I then just put it in the code for each tab? Just wondering what best practices are since I am new to programming. Thanks.

like image 466
Crystal Avatar asked Oct 25 '10 16:10

Crystal


People also ask

What is CLLocationManager in Swift?

Overview. A CLLocationManager object is the central place to manage your app's location-related behaviors. Use a location-manager object to configure, start, and stop location services. You might use these services to: Track large or small changes in the user's current location with a configurable degree of accuracy.

How do I ask for location permissions in iOS?

Here we will be using when-in-use authorization: Request authorization to use location services only when your app is running. Step 1 − Open Xcode, Single View Application, name it LocationServices. Step 2 − Open the Main. storyboard and add one button and name it getLocation.

What is NSLocationWhenInUseUsageDescription?

NSLocationWhenInUseUsageDescription. A message that tells the user why the app is requesting access to the user's location information while the app is running in the foreground.


1 Answers

I don't agree with John, the AppDelegate is the "easy" way to do it, but not always the better.

I would do this with a singleton. You can look at Matt Gallagher's article on Singletons, AppDelegates and top-level data for reference.

like image 52
gcamp Avatar answered Oct 23 '22 22:10

gcamp