首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >位置服务权限未保存iOS

位置服务权限未保存iOS
EN

Stack Overflow用户
提问于 2013-03-07 18:26:42
回答 1查看 165关注 0票数 2

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

这是我在GeoUtility类中的代码:

代码语言:javascript
复制
CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];

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

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

它是由viewDidAppear中的viewController触发的

我还在plist文件中的Required Devices Capabilites下添加了location-services

EN

回答 1

Stack Overflow用户

发布于 2013-03-07 19:51:30

添加CoreLocation.framework和MapKit.framework

.h中的

#import <MapKit/MapKit.h>

代码语言:javascript
复制
CLLocationManager *locationManager;
CLGeocoder *geocoder;

视图中的已加载

代码语言:javascript
复制
- (void)viewDidLoad
{
    locationManager = [[CLLocationManager alloc] init];
        geocoder = [[CLGeocoder alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [locationManager startUpdatingLocation];
}

先使用,然后使用

代码语言:javascript
复制
- (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。see down是您的应用程序名称,如果已关闭,则更改为ON

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15268675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档