1

我正在开发一个地理围栏应用程序,但它不起作用。

我得到了 didStartMonitoringForRegion 委托方法。通知和警报消息在 didStartMonitoringForRegion 中运行良好。但是,didEnterRegion 和 didExitRegion 没有被调用。

我把半径设置为200m,走了300多米,等了几分钟。但是 didExitRegion 没有工作,在返回实际位置时,也没有调用 didEnterRegion。

代码在下面给出。

- (void)viewDidLoad {

    [super viewDidLoad];


    locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;

    locationManager.distanceFilter = kCLDistanceFilterNone;

    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager requestAlwaysAuthorization];

    CLLocationCoordinate2D centers = CLLocationCoordinate2DMake(13.015624, 80.200276);    
    CLRegion *geoLoc = [[CLCircularRegion alloc]initWithCenter:centers radius:200.0                           
                                                       identifier:@"ident"];
    geoLoc.notifyOnExit = TRUE;

    geoLoc.notifyOnEntry = TRUE;

    [locationManager startUpdatingLocation];

    [locationManager startMonitoringForRegion:geoLoc desiredAccuracy:kCLLocationAccuracyBest];

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

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Message"
                                                    message:@"exit region"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
    [self testNotifications];

}

-(void) testNotifications {
    // function for the sample push notification
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {

    [self testNotifications];

}
- (void)locationManager:(CLLocationManager *)manager

didStartMonitoringForRegion:(CLRegion *)region {

    [self testNotifications];

   // alert code

    NSLog(@"Started Monitoring region:%f", region.center.latitude);
// the region and the given value is getting printed

}

任何关于如何从区域内外调用 didEnterRegion 和 didExitRegion 并显示通知/弹出窗口的建议将不胜感激!

4

0 回答 0