この問題に対処する一般的な方法は、AppDelegate を CLLocationManager デリゲートとして排他的に使用することです。AppDelegate のコールバック メソッドでは、特定の時点でアクティブな ViewController (存在する場合) を確認し、必要に応じてコールバック メソッドからその ViewController を呼び出します。
これを行うには、CoreLocation サービスを使用する各 ViewController の AppDelegate でプロパティを作成する必要があります。
@interface MyAppDelegate : UIResponder <CLLocationManagerDelegate>
@property (strong, nonatomic) FirstViewController *firstViewController;
@property (strong, nonatomic) SecondViewController *secondViewController;
@end
次に、ViewController が読み込まれるときに対応するプロパティを設定します。このような:
- (void)viewDidLoad
{
[super viewDidLoad];
MyAppDelegate *appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.firstViewController = self;
...
}
これが完了したら、コールバックを MyAppDelegate に排他的に登録できますが、次のように個々の ViewController に渡します。
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
if (self.firstViewController != Nil) {
[self locationManager:manager didEnterRegion:region];
}
}