gpt4 book ai didi

ios - CL位置管理器未返回位置

转载 作者:行者123 更新时间:2023-11-29 02:13:10 27 4
gpt4 key购买 nike

我试图在我的 viewDidLoad 方法中使用此代码获取当前位置:

//init the location manager
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[locationManager startUpdatingLocation];

我有我的委托(delegate)方法:

//if it fails to get the location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
self.currentLocation = newLocation;

}

我的 UIViewController 符合 CLLocationManagerDelegate 但是我没有任何事件,没有 NSLog 或错误。我已经在设备上进行了测试。有人可以告诉我这里可能出了什么问题吗?

最佳答案

确保您遵循文档中的指南

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

尤其是“UIRequiredDeviceCapabilities”键在您的 Info.plist 中。

关于ios - CL位置管理器未返回位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060167/

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