繁体   English   中英

定位服务权限未保存到iOS

[英]Location Services permission don't get saved iOS

我在Core Location Services中的本地化API有问题。 我收到请求位置服务权限的提示。 如果单击“允许”并转到“设置”,我可以看到我的应用没有权限。

这是我的GeoUtility类中的代码:

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

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

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

由viewDidAppear中的viewController触发

我还在plist文件的“必需的设备功能”下添加了location-services

添加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 {
        }
    } ];
}

您还可以在模拟器中更改设置,转到设置,然后选择定位服务,将其更改为开。 如果您的应用程序名称关闭,请查看它,然后更改为ON

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM