CLLocationManager 不调用 didEnterRegion,尽管注册了区域跟踪



我真的很犹豫要不要发布关于这个主题的第四个问题,但根据以前的答案对所有内容进行了三重检查,但仍然得到不好的结果。

问题:CLLocationManager 不会在 iOS6 中调用 didEnterRegion

设置:iOS6。

这是包含与CLLocationManager相关的所有函数的代码

myMapViewController.h

@interface FirstViewController : UIViewController <UIApplicationDelegate,CLLocationManagerDelegate, MKMapViewDelegate, UISearchBarDelegate,RKObjectLoaderDelegate >
{
    /* variables */
}
@property (strong, nonatomic) CLLocationManager *locationManager;

myMapViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
  /*  other initialization code */
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager setDistanceFilter: kCLLocationAccuracyBest];
    [locationManager setDesiredAccuracy: kCLLocationAccuracyBest];

}

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
  /*  other application code */
     Step* step = [_steps lastObject];    
    CLRegion *tmpReg = [[CLRegion alloc] initCircularRegionWithCenter:step.start_location.coordinate radius:1000 identifier: [step.start_locationLat stringValue] ];
    [locationManager startMonitoringForRegion:tmpReg];
    NSLog(@"Setting region with latitude %f", tmpReg.center.latitude);
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{
        NSLog(@"Monitoring region with latitude %f", region.center.latitude);
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{ 
    NSLog(@"ENTERED REGION!");
    }       
}

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

应用程序在零警告的情况下运行,以下是日志:

2012-12-02 19:31:41.449 myApp[5695:c07] Setting region with latitude 37.785690
2012-12-02 19:31:41.506 myApp[5695:c07] Monitoring region with latitude 37.785690

你进入该地区了吗?您的问题实际上并没有说您正在将设备移入和移出您正在监视的区域,或通过 Xcode 模拟该移动。

你没有忘记把[locationManager startUpdatingLocation]; ??

相关内容

  • 没有找到相关文章