ロケーションマネージャーのinitでstartMonitoringSignificantLocationChangesを呼び出します。
ロケーションイベントがある場合、didFinishLaunchingWithOptionsが起動され、次のコードが実行されると思います。(バックグラウンドモードとアプリが終了した場合を含む)
アプリがフリーズします(バックグラウンドで数時間後に別の場所でアプリを起動しようとすると黒い画面になります)
おそらく、ロケーションイベントを取得したときに何か問題が発生しています。誰かが何が問題なのか考えてくれれば幸いです。
ちなみに、この種のロケーションイベントをシミュレートする方法はありませんが、異なるセルタワーを持つ別のロケーションに物理的に移動します。ある?... :(
LocationController.m:
- (id)init
{
self = [super init];
if (self != nil) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[self.locationManager startUpdatingLocation];
[self.locationManager startMonitoringSignificantLocationChanges];
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(stop) userInfo:nil repeats:NO];
}
return self;
}
appdelegate.m :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
[[LocationController sharedInstance] startMonitoringSignificantLocationChanges];
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
[self updateLocationService];
return YES;
}
}
- (void) updateLocationService {
[[LocationController sharedInstance] start];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(stop) userInfo:nil repeats:NO];
}
- (void) stop {
[[LocationController sharedInstance] stop];
}
ありがとうございました!