iOS 8 Parse.com更新和pf geopoint当前位置 [英] iOS 8 Parse.com update and pf geopoint current location

查看:124
本文介绍了iOS 8 Parse.com更新和pf geopoint当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近更新到了与iOS 8兼容的最新Parse SDK,我添加了两个密钥NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription ...但由于某种原因[PFGeoPoint geopointForCurrentLocationInBackground]没有被调用....我不知道了解原因。

So I recently updated to the latest Parse SDK that's compatible with iOS 8 and I add the two keys NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription...but for some reason [PFGeoPoint geopointForCurrentLocationInBackground] is not being called....and I don't understand why.

这里是一段代码:

                     [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 时才会被调用订婚并已要求用户许可显示其位置。

[PFGeoPoint geopointForCurrentLocationInBackground] will only be called if you have first called your CLLocationManager engaged and have asked the user for permission to show their location.

您还需要更新(void)locationManager:(CLLocationManager *)管理器didChangeAuthorizationStatus:(CLAuthorizationStatus)状态适用于iOS 8的方法。

You also need to update the (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status method for iOS 8.

我使用的是这样的东西:

Something like this is what I use:

// 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委托方法来处理更改是位置授权状态,如下所示:

You also need to implement the locationmanager delegate method to handle changes is location authorization status, like so:

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

这篇关于iOS 8 Parse.com更新和pf geopoint当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆