首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >locationManager didExitRegion或locationManager didEnterRegion从未调用过

locationManager didExitRegion或locationManager didEnterRegion从未调用过
EN

Stack Overflow用户
提问于 2015-11-29 21:50:57
回答 2查看 471关注 0票数 2
代码语言:javascript
复制
   - (void)viewDidLoad
{

    [super viewDidLoad];

     if([CLLocationManager locationServicesEnabled]){

        self.locationManager = [[CLLocationManager alloc] init];

        self.locationManager.delegate = self;

        CLLocationCoordinate2D companyCenter;

        companyCenter.latitude = 23.126272;

        companyCenter.longitude = 113.395568;


        CLRegion* fkit = [[CLCircularRegion alloc] initWithCenter:companyCenter
                                                           radius:500 identifier:@"fkit"];
        [self.locationManager startMonitoringForRegion:fkit];

    }else{
        NSLog(@"not support");
    }

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"Error : %@",error);
}

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
    NSLog(@"Region monitoring failed with error: %@", [error localizedDescription]);
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(nonnull CLRegion *)region
{
    NSLog(@"Entered Region - %@", region.identifier);
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(nonnull CLRegion *)region
{
    NSLog(@"Entered Enter Region - %@", region.identifier);
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
    NSLog(@"Started monitoring %@ region", region.identifier);
}

上面是我的代码。我在模拟器中运行,没有位置,然后在调试委派项中设置了客户位置(23.126272,113.395568),它从不调用didEnterRegion ->location。有人能帮我吗?PS:我的Xcode是7.1.1,控制台日志“开始监控fkit region”

EN

回答 2

Stack Overflow用户

发布于 2015-11-29 22:48:46

你遗漏了一些步骤。你必须向你的info.plist添加一个条目,声明当你的应用程序在前台时,你想使用定位服务,(使用NSLocationWhenInUseUsageDescription键),然后你需要检查你是否有权限,如果你没有权限,就请求它。

在Xcode文档中搜索字符串"Requesting Permission to Use Location Services“以获取更多信息。

票数 0
EN

Stack Overflow用户

发布于 2016-04-18 17:20:19

在didStartMonitoringForRegion中添加此行

代码语言:javascript
复制
[self.locationManager requestStateForRegion:yourregion];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33983541

复制
相关文章

相似问题

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