CLLocationManager *_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest; //add by zhangzhenqiang
_locationManager.activityType = CLActivityTypeFitness;
_locationManager.distanceFilter = 1000.0;
_locationManager.pausesLocationUpdatesAutomatically = YES;
if (CurrentSystemVersion >= 8.0)
{
[appDelegate.locationManager requestAlwaysAuthorization];
[appDelegate.locationManager startUpdatingLocation];
}
else
{
[appDelegate.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status)
{ case kCLAuthorizationStatusNotDetermined:
if ([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[_locationManager requestWhenInUseAuthorization];
}
break;
default:
break;
}
}