iOS的位置更新我想寫像定位跟蹤應用程序「查找我的iPhone」在前臺,後臺運行,甚至終止(不運行)。位置將定期發送到我的服務器。我已經在谷歌搜索和閱讀許多文件,教程的意見,代碼關於這個話題。然後我找到了this tutorial。但在本教程中,位置被髮送到前臺和後臺的「.txt」文件沒有終止 ...我的意思是,當應用程序被殺害後,它不會在後臺重新發送位置「.txt」文件。 。因此,我添加並更新了一些代碼,以便在它未運行時發送位置信息。但是,我沒有這樣做......我的意思是,當我在多任務處理中(關閉)應用程序(雙擊主頁按鈕)時,它不發送到位置...即使應用程序沒有運行(如查找我的iPhone)
你能幫我嗎,我該如何解決這個問題?
在此先感謝
- (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];
}
嗯,好吧我的朋友..這個答案可能是我的失望:)我的應用程序只是要在前臺和後臺工作:/所以,可能會發生電池問題...再次感謝.. – xcoder123
好.. :)我是新的在stackoverflow,我不知道這個平臺的規則:)) – xcoder123