How to check if location services are enabled for a particular app prior to iOS 4.2?

后端 未结 3 1346
灰色年华
灰色年华 2020-12-23 16:57

How can I check if the user has allowed location for mu app? Normally I would use authorizationStatus method of the CLLocationManager class, but it

3条回答
  •  时光取名叫无心
    2020-12-23 17:27

    Hmm.. I didn't think to use authorizationStatus or locationServicesEnabled. What I did was the following:

    MKUserLocation *userLocation = mapView.userLocation;
    
    if (!userLocation.location) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" 
                                                        message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
    }
    

    I'm glad to see there's a better method to check, but I haven't had any problems with the way I detect if my app is allowed to use the GPS.

    Hope this helps!

提交回复
热议问题