Skip to content

Instantly share code, notes, and snippets.

@YGeorge
Last active August 29, 2015 14:14
Show Gist options
  • Save YGeorge/8230c8d13f3b93d2332e to your computer and use it in GitHub Desktop.
Save YGeorge/8230c8d13f3b93d2332e to your computer and use it in GitHub Desktop.
CLLocationManager startkit iOS 7,8
// didFinishLaunchingWithOptions or viewDidLoad:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
NSLog(@"authorizationStatus: %d", status);
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined &&
[locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager performSelector:@selector(requestAlwaysAuthorization) withObject:NULL];
} else {
[locationManager startUpdatingLocation];
}
//add to .h file:
- (CLLocation *)currentLocation;
//add to .m file:
#pragma mark - Location
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(@"didChangeAuthorizationStatus: %d", status);
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
if (status == kCLAuthorizationStatusAuthorizedAlways) {
[locationManager startUpdatingLocation];
}
}
}
- (CLLocation *)currentLocation {
NSLog(@"currentLocation: %.8f %.8f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude);
return locationManager.location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment