[英]AND operator in compound queries with GeoPoint Parse.com iOS
[英]iOS 8 Parse.com update and pf geopoint current location
所以我最近更新到與iOS 8兼容的最新Parse SDK,我添加了兩個密鑰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]; }
}];
有人可以幫忙嗎?
只有在您第一次調用CLLocationManager
並且已經要求用戶顯示其位置的權限時,才會調用[PFGeoPoint geopointForCurrentLocationInBackground]
。
您還需要為iOS 8更新(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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.