Last active
August 29, 2015 14:14
-
-
Save YGeorge/8230c8d13f3b93d2332e to your computer and use it in GitHub Desktop.
CLLocationManager startkit iOS 7,8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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