【问题标题】:didUpdateLocations is not called in ios 9.3.2在 ios 9.3.2 中未调用 didUpdateLocations
【发布时间】:2016-10-24 11:17:03
【问题描述】:

从不调用didUpdateLocations,而是使用拒绝代码kCLErrorDenied 调用didFailWithError。 以下是我所做的事情:

#import "ViewController.h"
@import CoreLocation;

@interface ViewController () <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    self.locationManager = [[CLLocationManager alloc] init];

    self.locationManager.delegate = self;

    // 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];

    }

    [self.locationManager startUpdatingLocation];
}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations

{

    NSLog(@"update");

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(nonnull NSError *)error

{

    NSLog(@"error");
}

@end

在应用的 info.plist 中插入了 NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription。在功能中启用背景模式并选择位置更新。从非常著名的博客post 获得帮助。我收到位置访问请求弹出窗口并允许应用访问位置。

但我无法获得位置更新。它适用于带有 IOS 8 的 IPAD,但不适用于带有 IOS 版本 9.3.2 的 ipad。如何在 IOS 9.3.2 中进行位置更新?

【问题讨论】:

  • 它在didFailWithError 中给出了什么错误?
  • @Ronak Chaniyara 更新了问题。我得到 kCLErrorDenied (Error Domain=kCLErrorDomain Code=0 “(null)”)

标签: objective-c cllocationmanager


【解决方案1】:

尝试以下方法可能会解决您的问题:

  • 转到设置并重置您的定位服务
  • 重置您的网络设置
  • 重启模拟器

另外,如果您选中了方案/编辑方案/选项/允许位置模拟,但没有设置默认位置。

如果使用 Always 授权,请将 NSLocationAlwaysUsageDescription 作为类型字符串添加到您的 plist。此外,如果使用 WhenInUse 授权,则对 NSLocationWhenInUseUsageDescription 执行相同的操作。

查看详细答案:

didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

IOS 9 Error Domain=kCLErrorDomain Code=0 "(null)"

【讨论】:

  • 我用的是真机调试。它适用于模拟器上的允许位置模拟,但不适用于真实设备。如我的问题中所述,我将 NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription 添加到 plist 中。我几乎阅读了所有 stackoverflow 帖子,但找不到解决方案。我应用了你说的东西,但没有用。
猜你喜欢
  • 2013-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-19
  • 2014-04-13
  • 2017-09-15
相关资源
最近更新 更多