Questions tagged «ios-background-mode»


9
定期的iOS背景位置更新
我正在编写一个需要高精度和低频更新背景位置的应用程序。解决方案似乎是后台NSTimer任务,该任务启动位置管理器的更新,然后立即关闭。曾有人问过这个问题: 如何在iOS应用程序中每n分钟获取一次后台位置更新? 应用程序进入后台运行后每隔N分钟获取一次用户位置 iOS不是典型的后台位置跟踪计时器问题 iOS长期运行的背景计时器,带有“位置”背景模式 基于位置跟踪的iOS全职后台服务 但是我还没有一个起码的例子。在尝试了上述公认答案的所有排列之后,我提出了一个起点。输入背景: - (void)applicationDidEnterBackground:(UIApplication *)application { self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ NSLog(@"ending background task"); [[UIApplication sharedApplication] endBackgroundTask:self.bgTask]; self.bgTask = UIBackgroundTaskInvalid; }]; self.timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self.locationManager selector:@selector(startUpdatingLocation) userInfo:nil repeats:YES]; } 和委托方法: - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"%@", newLocation); NSLog(@"background time: %f", [UIApplication …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.