gpt4 book ai didi

ios - CoreLocation 在 iOS 8 中不起作用

转载 作者:行者123 更新时间:2023-11-28 21:55:45 26 4
gpt4 key购买 nike

我在我的应用中使用定位服务。

但是 [CLLocationManager authorizationStatus]kCLAuthorizationStatusNotDetermined 都在 [self.locationManager startUpdatingLocation];

之前

项目代码:

实现

#import <CoreLocation/CoreLocation.h> 
@interface NewRunViewController () <CLLocationManagerDelegate>

@property (nonatomic, strong) CLLocationManager *locationManager;

- (void)viewDidLoad
{
[super viewDidLoad];

[self startLocationUpdates];
}

- (void)startLocationUpdates
{
// Create the location manager if this object does not
// already have one.
if (self.locationManager == nil) {
self.locationManager = [[CLLocationManager alloc] init];
}

self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = 10;

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
}

我还将 NSLocationWhenInUseUsageDescription 键添加到 info.plist 文件中。并且应用程序也不会请求用户许可来使用核心位置服务。谁能帮帮我??

最佳答案

您必须为目标的键 NSLocationAlwaysUsageDescription 包含一个字符串值。

在 Xcode 中查看目标的信息页面。当系统要求用户允许在您的应用中使用位置服务时,该字符串将成为警报文本。

这是我自己的处理代码。它正在请求始终授权,但您可以将其替换为使用时。

  CLAuthorizationStatus auth = [CLLocationManager authorizationStatus];
if (auth == kCLAuthorizationStatusNotDetermined && [self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager performSelector:@selector(requestAlwaysAuthorization) withObject:NULL];
} else {
if (auth == kCLAuthorizationStatusAuthorizedAlways) {
[self notificationsSetup];
} else {
NSLog(@"Device is not authorized for proper use of the location Services, no logging will be performed");
}
}

您可能会发现我的 github 存储库很有帮助- TTLocationHandler on Githup

关于ios - CoreLocation 在 iOS 8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26653503/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com