我尝试在我的应用中使用区域监控,据我了解,这会触发两种方法didEnterRegion
和didExitRegion
,即使应用甚至不在后台。
因此,这可能导致在没有任何应用程序感知的情况下调用函数,就好像这些函数只是使用基本应用程序环境调用的代码块,但是它们周围的所有函数都是无效的。例如,如果我们创建了一个CLLocationManager,那么它现在已经无效了,我们需要创建一个新的。
我需要做的是从CLLocationManager获取当前位置,但是我可以使用它吗?
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 0;
[locationManager startUpdatingLocation];
CLLocation *currentLocation = [locationManager location];
currentLocation
会保持一个好的价值还是只会在委托方法didUpdateLocations
中发生?
答案 0 :(得分:0)
区域监测期间持续存在的问题是该地区。当应用程序处于活动状态时,将通过 位置管理器(不一定是 启动监控的位置管理器)来调用代理。
如果应用程序在后台启动,它应检测到它是否已启动以进行区域监控并创建位置管理器(以及处理事件所需的任何其他内容)。