Mohammed Hussain Mohammed Hussain - 4 months ago 27
iOS Question

Want to enable location services through xcode

I'm new in ios and I want to know how can I enable location services through programming when I'm using this below....

enter image description here

As I'm using this label to show Whenever location service is disabled And an enable button(Green) to enable location services.But how to this programmatically.How will I get to know Location services are disabled and how the button will enable this.Please help me out.


you can use CLLocationManager's locationServicesEnabled property to check the system-wide/overall availability. Use your CLLocationManagerDelegate's locationManager: didFailWithError: method and check for a kCLErrorDenied error to see if the user denied location services.

if([CLLocationManager locationServicesEnabled]){

           NSLog(@"Location Services Enabled");

           if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
                 [[[UIAlertView alloc] initWithTitle:@"App Permission Denied" 
                                                        message:@"To re-enable, please go to Settings and turn on Location Service for this app." 



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


if location service disable for your app then its give you error

Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.)"


if user denied the permission, we cant enable in programmatically, user can manually enable the location services, for more reference