Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if location services are enabled for a particular app in iOS 7?

I want to check Location Service is on/off for my application,because when I turn locaiton Service to ON but application service is off so` how can I check it by code.

Please help to solve my problem.

Thanks in Advance.

like image 583
Jignesh Patel Avatar asked Apr 21 '14 09:04

Jignesh Patel


Video Answer


2 Answers

For those who are attempting to do this in swift.

if CLLocationManager.locationServicesEnabled() {
    switch(CLLocationManager.authorizationStatus()) {
    case .NotDetermined, .Restricted, .Denied:
        println("No access")
    case .AuthorizedAlways, .AuthorizedWhenInUse:
        println("Access")
    default:
        println("...")
    }
} else {
    println("Location services are not enabled")
}
like image 178
JJohnston Avatar answered Nov 14 '22 22:11

JJohnston


In the locationManager:didFailWithError:,

Add this:

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{


    if([CLLocationManager locationServicesEnabled])
    {
        NSLog(@"Enabled");

        if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied)
        {
             NSLog(@"Permission Denied");
        }
    }
 }
like image 45
NKB Avatar answered Nov 14 '22 22:11

NKB