Ios CLLocationManager未在初始位置激发区域

Ios CLLocationManager未在初始位置激发区域,ios,objective-c,cllocationmanager,Ios,Objective C,Cllocationmanager,我正在创建一个监控后台区域的应用程序,我可以在应用程序内外接收didEnterRegion和didextregion。我的一个问题是,在测试过程中,我有一个区域就在我工作的地方,当我启动应用程序时(我在启动和退出时清除这些区域),我希望didEnterRegion为这个区域触发,但它不是。显然,系统认为我在该区域内,但是,因为当我离开该区域时,我将收到didExitRegion。如果我再回到这个区域,它会像它应该的那样触发 我在初始化过程中尝试过使用requestStateForRegion,如

我正在创建一个监控后台区域的应用程序,我可以在应用程序内外接收
didEnterRegion
didextregion
。我的一个问题是,在测试过程中,我有一个区域就在我工作的地方,当我启动应用程序时(我在启动和退出时清除这些区域),我希望
didEnterRegion
为这个区域触发,但它不是。显然,系统认为我在该区域内,但是,因为当我离开该区域时,我将收到
didExitRegion
。如果我再回到这个区域,它会像它应该的那样触发

我在初始化过程中尝试过使用
requestStateForRegion
,如下所示:

[self.locationManager startMonitoringForRegion:region];
[self.locationManager requestStateForRegion:region];
然后将回调实现为:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    if (state == CLRegionStateInside) {
        [self locationManager:manager didEnterRegion:region];
    }
}

但是这个回调永远不会触发,所以我不知道应该如何进行。

这非常简单:正如apple在文档中所述,只有边界事件才会触发委托方法调用

但你为什么需要这个?如果你知道这个地区,你可以在启动应用程序的时候测试你是否在里面,对吗

如果它是一个圆形区域,你可以继续这样做

CLLocation *myLocation = CURRENT_LOCATION; 
CLCircularRegion* region = YOUR_REGION;
CLLocation *regionCenter = [[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude];

if([region distanceFromLocation:regionCenter]<region.radius)
{
   // YOU ARE IN THE REGION!!
}

您可以尝试
[locationMgrObj requestStateForRegion:regionObj]
以获取
中的当前状态
中的[self.locationManager requestStateForRegion:region]


func locationManager(\manager:CLLocationManager,didStartMonitoringFor region:CLRegion)

我想我必须手动完成。我只是担心我自己的计算结果与系统的计算结果不符。例如,一些圆形区域的半径为25米,但系统会在100米的范围内触发这些区域(而且,没什么比这更好的了)。如果我没有弄错的话,手动计算不会考虑到这一点,在外圈(从25米到100米)会有一个死区?无论如何,第二段代码看起来很有希望,我会试试看!第二段代码实际上做的完全相同。边界条件也可能在100m处触发的原因是您位置的水平精度(myLocation.HorizontalAccurance)大于等于75m,因此计算:([region distanceFromLocation:regionCenter]需要一些测试,但该解决方案至少足够好。
CLLocation *myLocation = CURRENT_LOCATION; 
CLCircularRegion* region = YOUR_REGION;
if([region containsCoordinate:myLocation.coordinate])
{
   //YOU ARE IN THE REGION!!
}