3
我经历了如此多的链接,即使在此之后,我还没有找到获取经纬度的适当解决方案。当应用程序处于后台时向服务器发送经纬度
Periodic iOS background location updates
iOS long-running background timer with "location" background mode
我从一些链接和论坛尝试,但它正在为仅3分钟,然后应用程序完全不更新用户的位置。
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
//create new uiBackgroundTask
__block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
//and create new timer with async call:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[locationManager startUpdatingLocation];
NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(startTrackingBg) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
});
}
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// store data
CLLocation *newLocation = [locations lastObject];
//tell the centralManager that you want to deferred this updatedLocation
if (_isBackgroundMode && !_deferringUpdates)
{
_deferringUpdates = YES;
[locationManager allowDeferredLocationUpdatesUntilTraveled:CLLocationDistanceMax timeout:10];
}
}
@Santo ...请检查该bro..and试图帮助我.. http://stackoverflow.com/questions/37338466/sending-current-location-to-server-in-background- as-well-as-in-running-app- –
@SurajSukale首先让我知道,你在建立时是否获得了当前位置? – Santo
没有兄弟...其实我在这个应用程序开发非常新(第一次工作在这个特定的域位置)....你能帮我解决这个 –