Ios7 在后台延迟位置更新
我有一个在前台和后台收集位置数据的应用程序。为了节省电池,我想使用AllowDeferredLocationUpdatesUntiltTraveled属性,如中所述 从文档中,在前台设置AllowDeferredLocationUpdatesUntiltTraveled(基于时间和距离)。一旦应用程序进入后台,我们将不会收到常规位置更新,而是根据AllowDeferredLocationUpdatesUntiltTraveled接收它们 我已经实现了以下代码,但是延迟没有在后台被调用Ios7 在后台延迟位置更新,ios7,cllocationmanager,Ios7,Cllocationmanager,我有一个在前台和后台收集位置数据的应用程序。为了节省电池,我想使用AllowDeferredLocationUpdatesUntiltTraveled属性,如中所述 从文档中,在前台设置AllowDeferredLocationUpdatesUntiltTraveled(基于时间和距离)。一旦应用程序进入后台,我们将不会收到常规位置更新,而是根据AllowDeferredLocationUpdatesUntiltTraveled接收它们 我已经实现了以下代码,但是延迟没有在后台被调用 #prag
#pragma mark - Location Manager
-(void) setLocationManager
{
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
}
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"didUpdateLocations");
if (!deferringUpdates)
{
CLLocationDistance distance = 200;
NSTimeInterval time = 60;
[locationManager allowDeferredLocationUpdatesUntilTraveled:distance timeout:time];
deferringUpdates = YES;
}
}
-(void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error
{
NSLog(@"didFinishDeferredUpdatesWithError");
}
SetLocationManager在前台被调用,工作正常。一旦应用程序进入后台,我仍然会收到定期的位置更新,而不是AllowDeferredLocationUpdatesUntiltTraveled
我还在info.plist文件中设置了以下值
后台提取
背景位置更新
设备功能-位置服务
有人能实现这一点吗?您需要在didFinishDeferredUpdatesWithError:中将DelerringUpdates设置回NO。根据苹果的文档,每次调用(AllowDeferredLocationUpdatesUntiltTraveled)时,“代理的位置管理器:didFinishDeferredUpdatesWithError:方法被准确地调用一次
因此,AllowDeferredLocationUpdatesUntelTraveled只调用一次,直到deferringUpdates为NO。locationManager:DidFinishDeferredUpdatesWither:方法返回的
error
的值是多少?嘿@mobiletest,您是否能够解决该问题。如果是的话,你愿意在这里作为正确答案分享吗