2015-04-02 98 views
0

我试图做出基于区域的提醒。当我需要添加提醒时,我会弹出一个viewcontroller。在那个VC中,我选择一个需要提醒的区域,然后使用startMonitoringForRegion方法。我将locationManager委托设置为AppDelegate,以便AppDelegate可以响应输入或退出区域。
问题是,当我关闭viewcontroller委托方法不会被调用。我究竟做错了什么?
下面是代码:
AddReminderVCLocationmanager startmonitoringforregion不调用委托方法

self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; 
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:self.lastCenter radius:self.radius identifier:@"id"]; 
[self.locationManager startMonitoringForRegion:region]; 

的AppDelegate

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { 
    NSLog(@"EXIT REGION"); 
} 

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

注意,当AddReminderVC仍是可见的方法都被调用。只有当它被解雇时,委托方法才会起作用。

回答

0

您必须在您的AppDelegate中实例化locationManager或编写另一个Singleton类来保存locationManager。如果将其设置在viewController中,那么当没有更多引用时,弧将删除该对象。