Ios 为什么使用Cllocationmanager委托方法的地理围栏跟踪不调用

Ios 为什么使用Cllocationmanager委托方法的地理围栏跟踪不调用,ios,objective-c,cllocationmanager,Ios,Objective C,Cllocationmanager,嗨 我使用位置管理器实现了地理围栏 我在这里创建区域 在这里输入代码 在视图中,我创建了对象作为 //用于地理围栏跟踪 locationManager = [[CLLocationManager alloc] init]; [locationManager setDelegate:self]; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = kCLLocati

我使用位置管理器实现了地理围栏

我在这里创建区域

在这里输入代码

在视图中,我创建了对象作为

//用于地理围栏跟踪

locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
 locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyBest;
[locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];

-(void)TraceGeofenceLocation{
    for (int k=0; k< [self.chGeofenceType count]; k++) {
    NSString *chTracLati = [NSString stringWithFormat:@"%f",[[self.chGeofenceLatitudes objectAtIndex:k] doubleValue]];
    NSString *chTracLong = [NSString stringWithFormat:@"%f",[[self.chGeofeceLongitudes objectAtIndex:k] doubleValue]];
    NSString *chTracRadius = [NSString stringWithFormat:@"%f",[[self.chGeofenceRadius objectAtIndex:k] doubleValue]];
        CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(chTracLati.doubleValue, chTracLong.doubleValue);



        if ([[self.chGeofenceType objectAtIndex:k] intValue] == 1) {

                region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"Restricted"];
            }
            else if ([[self.chGeofenceType objectAtIndex:k] intValue] == 2){

                region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"SafeZone"];
            }
            else{
                region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"Curfew"];

            }
            [region setNotifyOnEntry:YES];
            [region setNotifyOnExit:YES];

            [locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];

        }

    }
}

我的委托方法更新位置正在调用,我进入控制台, 但进入区域、退出区域和退出区域都不是在呼唤

谁能帮帮我吗

提前感谢

StartupDating位置和StartMonitoring重要位置更改是互斥的。如果要进行startMonitoringSignificantLocationChanges以查找地理围栏,请确保首先调用StopUpdateLocation

还要注意的是,土工栅栏的探测并不是非常精确。平均而言,您可以获得数百米的分辨率。我发现打电话给didEnterRegion通常需要几分钟,如果有的话

注意:您当前正在调用[locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];这方面的问题是KCallocationAccuracyBest是一个非常小的区域。(KCLLOCATIONACURACYBEST代码的值为1.0)。这意味着您要求系统在您进入直径为1.0米的区域时通知您。由于土工栅栏探测的精度高达数百米,因此可能永远不会被称为。相反,您应该将精度设置为更低的值:[locationManager startMonitoringForRegion:region desiredAccuracy:200.0]

祝你好运

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {

    locationnew = locations.lastObject;
    self.Latit=[NSString stringWithFormat:@"%f", locationnew.coordinate.latitude];
    self.Longi=[NSString stringWithFormat:@"%f",locationnew.coordinate.longitude];
    Speed = [[NSString stringWithFormat:@"%f",[locationnew speed]] floatValue];

    NSLog(@"Speed :%f Latitude :%@ Longitude :%@",Speed,self.Latit,self.Longi);
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{

    if ([region.identifier isEqualToString:@"Restricted"]) {

        [self sendNotificationtoServerwithtype:@"1"];
    }

    else  if ([region.identifier isEqualToString:@"Curfew"]){

        [self sendNotificationtoServerwithtype:@"3"];
    }

}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {

       if ([region.identifier isEqualToString:@"SafeZone"]){

        [self sendNotificationtoServerwithtype:@"2"];
    }

}


- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    if (state == CLRegionStateInside){
        NSLog(@"is in target region");

    }else{
        NSLog(@"is out of target region");
    }

}