我想编写位置跟踪应用程序,例如“查找我的 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];
}