Created
May 5, 2016 03:26
-
-
Save nfarah86/c3d78fb0b2d9d8255609bb4b45787291 to your computer and use it in GitHub Desktop.
Get User's Location
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
// omitted code | |
- (void)startStandardUpdates | |
{ | |
if (![CLLocationManager locationServicesEnabled]) { | |
NSLog(@"Location services are not available (or are disabled for this app)."); | |
} | |
else { | |
self.locationManager = [[CLLocationManager alloc] init]; | |
self.locationManager.delegate = self; | |
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; | |
self.locationManager.distanceFilter = 0; | |
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { | |
NSLog(@"Running on iOS 8 or newer. Will request constant tracking authorization."); | |
[self.locationManager requestAlwaysAuthorization]; | |
} | |
else { | |
NSLog(@"Running on iOS 7 or older. Will attempt to start updating location immediately."); | |
[self.locationManager startMonitoringSignificantLocationChanges]; | |
[self.locationManager startUpdatingLocation]; | |
} | |
} | |
} | |
// omitted code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment