我想在后台发布数据,并且我希望从常规间隔中接收响应,以便我尝试使用CLLocation Manager。但didUpdateToLocation方法只调用一次。 请推荐我! 进入这里位置背景 - 网络连接
- (void)applicationDidEnterBackgroundUIApplication *)application
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m
[locationManager startUpdatingLocation];
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_ QUEUE_PRIORITY_DEFAULT, 0), ^{
//Do the work associated with the task
// code for Posting Data Here
NSLog(@"backgroundTimeRemaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
- (void)locationManagerCLLocationManager *)manager
didUpdateToLocationCLLocation *)newLocation
fromLocationCLLocation *)oldLocation
{
NSLog(@"Location Change");
}
This Method Call Only Once.
有你在身边有些感动?我从经验中知道,即使使用kCLDistanceFilterNone,您可能需要移动得相当远(有时超过30米)才能实际发送更新。 –
根据你的位置更新locationManager.distanceFilter值应该是什么。 – Vijay
这是一个很好的价值。但是,根据您的位置,手机可能无法很好地修复您的位置。因此,即使每当它移动一米时它都会通知您,但它可能不知道它已经移动了一米。 –