0

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.

mychar
  • 1,031
  • 1
  • 11
  • 20

2 Answers2

2

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..

Charan Giri
  • 1,097
  • 1
  • 9
  • 15
  • Currently i use singleton class for location manger.When user start updatelocation manager.It should work on background state every day.can't stop it.One thing i want to ask.can i change the desiredAccuracy after setup the delegate.Because some times location update distance may be change.Then i can save energy from that.My big issue is battery.another thing i heard some times location manger pause automatically in background mode – mychar Apr 01 '14 at 04:38
  • once we set request for location manager in Plist location manger will not pause automatically in background mode.(I used this for one of my apps). As you said you used singleton class for location manger here location will update no problem with this. If you want to change desiredAccuracy then keep it in a shared place where you can access and set value from any part of your application, So once you change some where it will automatically updates in singleton class. – Charan Giri Apr 01 '14 at 05:14
  • Ok thanks what about the battery its call location manger every 20meters user move – mychar Apr 01 '14 at 05:35
  • by using timer like after 1 min call [locationManager StartUpdating]; and then check distance and then again stopping location manager we can do this way but the main issues is like one can't be sure about in 1 min user can travel more/less than 20 meter(traveling in car/on foot). This is risky to calculate. I'm not sure about saving battery while using location manager in background state.. i'll try and if i found a solution i'll let you know – Charan Giri Apr 01 '14 at 05:42
  • what about set desiredAccuracy as 20m then location manager automatically check for every 20 meters – mychar Apr 01 '14 at 05:52
  • do u have a solution.still i didn fine better solution.still battery down fastly – mychar Apr 14 '14 at 04:08
1

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

Community
  • 1
  • 1