iOS 8 Parse.com更新和pf geopoint当前位置

所以我最近更新到最新的parsingSDK,与iOS 8兼容,我添加了两个键NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription …但出于某种原因[PFGeoPoint geopointForCurrentLocationInBackground]不被称为….我不明白为什么。

在这里输入图像说明

这里是代码片段:

[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]; } }]; 

有人可以帮忙吗?

[PFGeoPoint geopointForCurrentLocationInBackground]只会在您首次调用您的CLLocationManager并要求用户显示其位置的权限时才会被调用。

您还需要更新iOS(8 (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status方法。

像这样的东西是我用的:

 // 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>> } 

您还需要实施locationmanager委托方法来处理更改是位置授权状态,如下所示:

 - (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; } }