フォアグラウンド、バックグラウンド、さらには終了 (実行されていない)で実行される「私の iPhone を見つける」のような位置追跡アプリを作成したいと考えています。場所は定期的にサーバーに送信されます。私はグーグルで検索し、このトピックに関する多くのドキュメント、チュートリアルのコメント、コードを読みました。次に、このチュートリアルを見つけました。しかし、このチュートリアルでは、場所はフォアグラウンドで「.txt」ファイルに送信され、バックグラウンドは終了しません...つまり、アプリが強制終了されると、バックグラウンドで再起動されて位置情報「.txt」ファイルが送信されません..そのため、実行されていないときに位置情報を送信するためにいくつかのコードを追加および更新しました..しかし、私はそれをしなかった... つまり、マルチタスクでアプリを強制終了(閉じる)すると(ホームボタンをダブルタップ)、場所に送信されません...
どうすればこの問題を解決できますか?
前もって感謝します
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[self log:[NSString stringWithFormat:@"Background location %.06f %.06f %@" , newLocation.coordinate.latitude, newLocation.coordinate.longitude, newLocation.timestamp]];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
// create a new manager and start checking for sig changes
[self log:@"didFinishLaunchingWithOptions location key"];
m_locManager = [[CLLocationManager alloc] init];
[self log:@"didFinishLaunchingWithOptions created manager"];
m_locManager.delegate = self;
[self log:@"didFinishLaunchingWithOptions set delegate"];
[m_locManager startMonitoringSignificantLocationChanges];
[self log:@"didFinishLaunchingWithOptions monitoring sig changes"];
return YES;
}
[self log:@"didFinishLaunchingWithOptions"];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
[self log:@"applicationWillResignActive"];
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:viewController.m_significantSwitch.on forKey:@"significant"];
[userDefaults synchronize];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[self log:@"applicationDidEnterBackground"];
[m_locManager startMonitoringSignificantLocationChanges];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
[self log:@"applicationWillEnterForeground"];
[m_locManager stopMonitoringSignificantLocationChanges];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self log:@"applicationDidBecomeActive"];
if (![window.subviews count])
{
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
viewController.m_significantSwitch.on = [userDefaults boolForKey:@"significant"];
if (viewController.m_significantSwitch.on)
[viewController actionSignificant:nil];
}
}
- (void)applicationWillTerminate:(UIApplication *)application {
[self log:@"applicationWillTerminate"];
[m_locManager startMonitoringSignificantLocationChanges];
}