簡體   English   中英

Locationmanager startmonitoringforregion不調用委托方法

[英]Locationmanager startmonitoringforregion not calling delegate methods

我正在嘗試基於區域的提醒。 我有一個需要添加提醒時彈出的ViewController。 在該vc中,我選擇需要提醒的區域,然后使用startMonitoringForRegion方法。 我將locationManager委托設置為AppDelegate,以便AppDelegate可以響應進入或退出區域。
問題是當我關閉viewcontroller時,不會調用委托方法。 我究竟做錯了什么?
這是代碼:
AddReminderVC

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仍然可見時,方法會被調用。 只有當它被解雇時,委托方法才起作用。

您必須在AppDelegate中實例化locationManager或編寫另一個Singleton類來保存locationManager。 如果在viewController中進行設置,則在沒有更多引用時,弧將刪除該對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM