Reputation: 149
//View did Load Method- LocationManager is allocated and have included the CLLocationManagerDelegate in .h File
-ViewDidLoad{ self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; self.locationManager.distanceFilter=kCLDistanceFilterNone; [self.locationManager requestWhenInUseAuthorization]; [self.locationManager startMonitoringSignificantLocationChanges]; [self.locationManager startUpdatingLocation]; } // Location Manager Delegate Methods - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { NSLog(@"%@", [locations lastObject]); }
Upvotes: 1
Views: 170
Reputation: 14571
In plist you have to add 2 entries
Make the string of both as "Location is required to find out where you are" or anything
self.locationManager = [[CLLocationManager alloc]init];
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if (authorizationStatus == kCLAuthorizationStatusAuthorized ||
authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"You are authorized");
}
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
Hope this helps
Upvotes: 3