永远不会调用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
将 NSLocationWhenInUseUsageDescription
和 NSLocationAlwaysUsageDescription
插入到应用的info.plist中 . 在选择了位置更新的功能中启用后台模式 . 从非常着名的博客post获得帮助 . 我收到位置访问请求弹出窗口并允许该应用访问位置 .
但我无法获得位置更新 . 它适用于IOS 8的IPAD,但不适用于IOS版本9.3.2的ipad . 如何在IOS 9.3.2中进行位置更新?
1 回答
尝试以下事项可能会解决您的问题:
转到设置并重置您的位置服务
重置您的网络设置
重启模拟器
此外,如果您已选中方案/编辑方案/选项/允许位置模拟,但没有设置默认位置 .
如果使用始终授权,请将
NSLocationAlwaysUsageDescription
添加到plist作为类型字符串 . 此外,如果使用WhenInUse授权,请以相同的方式执行相同的操作 .详情请查看答案:
didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
和IOS 9 Error Domain=kCLErrorDomain Code=0 "(null)"