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中进行位置更新?
答案 0 :(得分:0)
尝试以下事项可能会解决您的问题:
另外,如果您选中了Scheme / Edit Scheme / Options / Allow Location Simulation,但没有设置默认位置。
如果使用“始终授权”,则将NSLocationAlwaysUsageDescription
作为类型字符串添加到plist中。另外,如果使用WhenInUse授权,请以NSLocationWhenInUseUsageDescription
相同的方式执行相同操作。
详细检查答案: