【问题标题】:How to make my ios app appears in Location Services in the settings如何让我的 ios 应用程序出现在设置中的位置服务中
【发布时间】:2012-06-19 14:33:20
【问题描述】:

我写了一个 CLLocationManager ios 应用程序。但是,我在 iPhone 的设置中看不到我的应用程序出现在定位服务中。我是否需要在 Xcode 的 ios 项目中的 plist 中设置特定值?提前致谢!

【问题讨论】:

    标签: ios ios5 cllocationmanager


    【解决方案1】:

    在iOS -8 需要做一些改动:

    locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
            [locationManager requestWhenInUseAuthorization];
        }else{
            [locationManager startUpdatingLocation];
        }
    

    需要在 plist 中添加 2 个带有空白值的额外键 1)NSLocationWhenInUseUsageDescription 2)NSLocationAlwaysUsageDescription

    #pragma mark - CLLocationManagerDelegate
    
    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
        NSLog(@"didFailWithError: %@", error);
        UIAlertView *errorAlert = [[UIAlertView alloc]
                                   initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
    }
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        NSLog(@"didUpdateToLocation: %@", newLocation);
        CLLocation *currentLocation = newLocation;
    
        if (currentLocation != nil) {
            NSString *strLat = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
            NSString *strLong = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
        }
    }
    

    【讨论】:

      【解决方案2】:

      一旦调用实际需要位置跟踪的代码,它应该会自动出现(每当弹出窗口第一次显示:你允许...)

      尝试这样调用:

      [self.locationManager startUpdatingLocation];
      

      应该这样做

      【讨论】:

        猜你喜欢
        • 2012-05-06
        • 1970-01-01
        • 1970-01-01
        • 2013-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-12
        • 2012-02-15
        相关资源
        最近更新 更多