Checking for iOS Location Services

后端 未结 4 2030
别那么骄傲
别那么骄傲 2020-12-23 10:28

I have a view with a map and a button (like the Maps app once) that allows the user to center and zoom his current location on the map. If I can not use the locationServices

相关标签:
4条回答
  • 2020-12-23 11:02

    I run into this problem too and still be finding the answer.

    take care that authorizationStatus requires iOS4.2+ and + (BOOL)locationServicesEnabled requires iOS4.0... And for previous iOS versions, it is - (BOOL)locationServicesEnabled...

    0 讨论(0)
  • 2020-12-23 11:03

    "locationServicesEnabled" checks if the user has enabled Location Services in Preferences. Your MapView probably checks this value already and should not set any values to "self.mapView.userLocation" if Location Services are not available. This SO question might give you some more info.

    0 讨论(0)
  • 2020-12-23 11:16

    In Preferences you have two options to disable the location services. The first option is a global switch to disable the location service for all apps "[CLLocationManager locationServicesEnabled]". The second option let you disable the location service for some apps but not for all apps.

    To check if its disabled globally and if its disabled for your app use following:

    if([CLLocationManager locationServicesEnabled] && 
       [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
    {
    ...
    }
    
    0 讨论(0)
  • 2020-12-23 11:23
    - (BOOL) enableLocationServices
    {
    
        if ([CLLocationManager locationServicesEnabled])
        {
            self.locationManager.distanceFilter = 10;
            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
            [self.locationManager startUpdatingLocation];
            [self.mapview setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
            return YES;
        }
        else
        {
            return NO;
        }
    }
    
    0 讨论(0)
提交回复
热议问题