【问题标题】:Location Fetching Error Ios [duplicate]位置获取错误 Ios [重复]
【发布时间】:2015-12-02 17:38:50
【问题描述】:

我在 iOS 7 上运行良好的应用程序不适用于 iOS 8 SDK。

CLLocationManager 不返回位置,我也没有在Settings -> Location Services 下看到我的应用程序。我对这个问题进行了谷歌搜索,但没有任何结果。有什么问题?

【问题讨论】:

标签: ios


【解决方案1】:

在 ios 8+ 中,您需要在应用程序中请求权限 [self.locationManager requestWhenInUseAuthorization] 仅为 us3 和 [self.locationManager requestAlwaysAuthorization] 以始终使用位置

这段代码在 ios 8 上完美运行

#pragma mark -
#pragma mark CLLocationManagerDelegate

- (void)startSignificantChangeUpdates
{
    if ([CLLocationManager locationServicesEnabled])
    {
        if (!self.locationManager)
           self.locationManager =  [[CLLocationManager alloc] init];


        self.locationManager.delegate = self;

        // request location when app in use
        [self.locationManager requestWhenInUseAuthorization];
        [self.locationManager startUpdatingLocation];
    }
}



- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
   [self.locationManager stopUpdatingLocation];

    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    for (CLPlacemark * placemark in placemarks) {
        NSString *country = placemark.ISOcountryCode;
        cityName = [placemark locality];
    }
    }];
}

【讨论】:

    【解决方案2】:

    在您的info.plist下面添加

    键:NSLocationWhenInUseUsageDescription 类型:String 值:提示消息 例如-需要您当前的位置

    【讨论】:

      猜你喜欢
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      相关资源
      最近更新 更多