iOS 8 CLLocationManager enterRegion:如果使用requestWhenInUseAuthorization则不会被调用 [英] iOS 8 CLLocationManager enterRegion: not getting called if use requestWhenInUseAuthorization

查看:460
本文介绍了iOS 8 CLLocationManager enterRegion:如果使用requestWhenInUseAuthorization则不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在iOS 8中为自定义区域调用委托方法locationManager:didEnterRegion。这是代码:

I'm trying to get being called the delegate method locationManager:didEnterRegion in iOS 8 for custom region. Here is the code:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}

CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(20, 20) radius:1000 identifier:@"asda"];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
[self.locationManager startMonitoringForRegion:region];

它调用方法 locationManager:didStartMonitoringForRegion ,但它不会调用enter或exit区域方法。

It does call method locationManager:didStartMonitoringForRegion, but it doesn't call "enter" or "exit" region methods.

另一个奇怪的事情是,如果我对locationManager使用requestAlwaysAuthorization,它会起作用。但是我需要使用何时使用。

The one more strange thing is that it DOES work if I use requestAlwaysAuthorization for locationManager. But I need to get it worked with "When In Use".

注意:在iOS7中,它适用于WhenInUse和Always Authorization方法。

Note: In iOS7 it works for both WhenInUse and Always Authorization methods.

推荐答案

区域监控 - 它无法使用 requestWhenInUseAuthorization

region monitoring - it's not working with requestWhenInUseAuthorization

检查Apple Docs:
..使用时......应用程序无法使用任何自动重启应用程序的服务,例如区域监控或重要位置更改服务

check Apple Docs: ".. "when-in-use" ... Apps cannot use any services that automatically relaunch the app, such as region monitoring or the significant location change service"

您必须致电 requestAlwaysAuthorization !!!
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization

You must call requestAlwaysAuthorization!!! https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization

这篇关于iOS 8 CLLocationManager enterRegion:如果使用requestWhenInUseAuthorization则不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆