How to check Location Manager is running or not in iOS App?


To check any services related to location in ios with swift we can use the CLLocationManager.

In this example we’ll see how to check if the location manager is running or not. We’ll do this with help of an sample project. So, create a new project. First we need to create a locationManager object, so in your view controller.

var locationManager = CLLocationManager()

Now, we first of all we need to check if the location services are enabled on the device or not. To check this we’ll use

CLLocationManager.locationServicesEnabled() function, which returns a Boolean value showing whether the location service on device is active or not.

if CLLocationManager.locationServicesEnabled() {
   print("permissions allowed")
} else {
   print(“permissions not allowed”)
}

In the example above, if the location services are enabled, then we print “permissions allowed”, otherwise we print that the permissions are not allowed.

Now, the corelocation manager or the CLLocationManager does not provide any method which could tell if the locations manager is running or not, i.e. it does not tell about the state of location manager.

But we can always make use of Location manager start monitoring method to start using location manager even if it is already running. It would not create multiple instances of that object as stated by the apple docs.

Updated on: 30-Jul-2019

300 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements