Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding out if location services are enabled is not working
    primarykey
    data
    text
    <p>I have an app which uses the device location. If they allow the location, I want to run my method <code>getDataFromJson</code> and run my app as normal. If they deny it, or have denied it before, I wish to show them a view explaining they need to go to settings and allow it.</p> <p>I have a lot of code, but it doesn't work at the moment. Can anyone help explain where the problem is?</p> <p>Many thanks!</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; if ([CLLocationManager authorizationStatus] == YES) { //are enabled, run the JSON request [self getDataFromJson]; } else { //is not enabled, so set it up NSLog(@"no"); [locationManager location]; }; } -(CLLocationCoordinate2D) getLocation{ locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = kCLDistanceFilterNone; [locationManager startUpdatingLocation]; CLLocation *location = [locationManager location]; CLLocationCoordinate2D coordinate = [location coordinate]; return coordinate; } -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { if (status == kCLAuthorizationStatusDenied) { //location denied, handle accordingly locationFailView.hidden = NO; mainView.hidden = YES; } else if (status == kCLAuthorizationStatusAuthorized) { //hooray! begin tracking [self getDataFromJson]; } } //class to convert JSON to NSData - (IBAction)getDataFromJson { CLLocationCoordinate2D coordinate = [self getLocation]; NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude]; NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude]; ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload