我想打,更新用戶的位置,以我的遠程服務器中的每XX分鐘的更新應用程序的位置,即使該應用程序在後臺 我曾嘗試下面的代碼後臺任務或iphone
- (void)applicationDidEnterBackground:(UIApplication *)application
{
i=0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
bgTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(backgroundTask:) userInfo:nil repeats:YES];
}
-(void)backgroundTask:(NSTimer*)timer{
i++;
NSLog(@"%s %d",__func__,i);
}
但大約10分鐘後,計時器回調停止 我怎樣才能讓連續到我的服務器更新當前位置的應用程序