【发布时间】: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 中插入了 NSLocationWhenInUseUsageDescription 和 NSLocationAlwaysUsageDescription。在功能中启用背景模式并选择位置更新。从非常著名的博客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