Parse.com iOS 8 update and current geodata location pf
So, I recently upgraded to the latest Parse SDK compatible with iOS 8 and I add two keys NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription ... but for some reason [PFGeoPoint geointForCurrentLocationInBackground] is not being called .... and I can't figure out why.
and here is the code snippet:
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
if(!error){
NSLog(@"Got current geopoint!");
....
else{
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:@"Oops!" message:[error description] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
[errorAlert show]; }
}];
Can anyone please help?
source to share
[PFGeoPoint geopointForCurrentLocationInBackground]
will only be called if you first called yours CLLocationManager
and asked the user for permission to show your location.
You also need to update the method (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
for iOS 8.
Something like this I am using:
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
else {
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
//<<PUT YOUR CODE HERE AFTER LOCATION IS UPDATING>>
}
You also need to implement the locationmanager delegate method to handle changes - this is the location authorization status, for example:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusDenied:
NSLog(@"kCLAuthorizationStatusDenied");
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Location Services Not Enabled" message:@"The app canβt access your current location.\n\nTo enable, please turn on location access in the Settings app under Location Services." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
}
break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
{
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
CLLocation *currentLocation = locationManager.location;
if (currentLocation) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setCurrentLocation:currentLocation];
}
}
break;
case kCLAuthorizationStatusAuthorizedAlways:
{
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
CLLocation *currentLocation = locationManager.location;
if (currentLocation) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setCurrentLocation:currentLocation];
}
}
break;
case kCLAuthorizationStatusNotDetermined:
NSLog(@"kCLAuthorizationStatusNotDetermined");
break;
case kCLAuthorizationStatusRestricted:
NSLog(@"kCLAuthorizationStatusRestricted");
break;
}
}
source to share