gpt4 book ai didi

iphone - 位置服务权限未保存 iOS

转载 作者:行者123 更新时间:2023-12-01 16:51:36 24 4
gpt4 key购买 nike

我对核心位置服务中的本地化 API 有疑问。我收到请求位置服务许可的提示。如果我单击允许并转到设置,我可以看到我的应用程序没有权限。

这是我在 GeoUtility 类中的代码:

CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];

CLLocationManager *lm = [[CLLocationManager alloc] init];

[lm setPurpose:@"Need to verify your region"];
[lm startUpdatingLocation];

它由 viewDidAppear 中的 viewController 触发

我还添加了 location-services在我的 plist 文件中的所需设备功能下。

最佳答案

添加 CoreLocation.framework 和 MapKit.framework



在.h
#import <MapKit/MapKit.h>

CLLocationManager *locationManager;
CLGeocoder *geocoder;

鉴于确实加载了
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
geocoder = [[CLGeocoder alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}

然后
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
LongitudeLbl.text = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.longitude];
LatitudeLbl.text = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.latitude];
}


[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
NSString *addresstemp2 = [[NSString alloc] init];
NSString *subThoroughfare2 = [NSString stringWithFormat:@"%@",placemark.subThoroughfare];

NSString *thoroughfare2 = [NSString stringWithFormat:@"%@",placemark.thoroughfare];
NSString *postalCode2 = [NSString stringWithFormat:@"%@",placemark.postalCode];
NSString *locality2 = [NSString stringWithFormat:@"%@",placemark.locality];
NSString *administrativeArea2 = [NSString stringWithFormat:@"%@",placemark.administrativeArea];
NSString *country2 = [NSString stringWithFormat:@"%@",placemark.country];

if (![subThoroughfare2 isEqualToString:@"(null)"]) {
addresstemp2 = [NSString stringWithFormat:@"%@",subThoroughfare2];
}
if (![thoroughfare2 isEqualToString:@"(null)"]) {
addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,thoroughfare2];
}
if (![postalCode2 isEqualToString:@"(null)"]) {
addresstemp2 = [NSString stringWithFormat:@"%@ %@",addresstemp2,postalCode2];
}
if (![locality2 isEqualToString:@"(null)"]) {
addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,locality2];
}
if (![administrativeArea2 isEqualToString:@"(null)"]) {
addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,administrativeArea2];
}
if (![country2 isEqualToString:@"(null)"]) {
addresstemp2 = [NSString stringWithFormat:@"%@ %@",addresstemp2,country2];
}
AddressLbl.text = [[NSString alloc] initWithString:addresstemp2];
[AddressLbl sizeToFit];

[locationManager stopUpdatingLocation];
} else {
}
} ];
}

您还可以更改模拟器中的设置转到设置并选择位置服务将其更改为打开。 see down 是您的应用程序名称,如果它关闭则更改为 ON

关于iphone - 位置服务权限未保存 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15268675/

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