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仍是可見的方法都被調用。只有當它被解僱時,委託方法纔會起作用。