Reputation: 1057
I want to check the user current location in every 20 meters user move.All in active state and background.I know its ok to do it in active state.But i want to know is it ok to do the same thing in background mode in ios.Specially want to know is apple reject this method.But in ios7 i think its ok
Actually i want to do get the currant location and if user move more than 1km call serve API ,if user move every 20m check with local data base pop up some data.
All i want to do it on both active state and background state. at the moment i m using significant location change and region monitoring.But region monitoring have lower accuracy.I want at leaset 20m accuracy. That why i try to do above method.I know that method give lot of battery drain. But i want accuracy best. Any one have idea.
Upvotes: 0
Views: 431
Reputation: 144
In AppDelegate.m file
- (void)applicationDidEnterBackground:(UIApplication *)application{
UIApplication* app = [UIApplication sharedApplication];
UIApplication *bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(al) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
});
}
-(void)al{
yourViewController *navigation=[[yourViewController alloc]initWithNibName:@"yourViewController" bundle:nil];
[navigation.locationManager startMonitoringSignificantLocationChanges];
}
Also try the following link: here
Upvotes: 1
Reputation: 1097
You can get user current location both active state and background state app will not get rejected. In plist you need to set request for getting user location in background state. Once this is set your location manger delegates will keep on calling (because of this there are many chances to get the battery drain quickly) write your location manager method in one class/appdelegate and reuse them, so that you can easily check condition (when ever user moves it will automatically updates user's location so you can check the distance between two points and if user reaches distention then you can prompt alert)
Hope this will help..
Upvotes: 2