I need to constantly monitor the position of an user to notify him when he gets near something interesting. Which is the correct way to achieve this?
I have not been abl
Disclaimer: I work for Cintric
We had a similar problem at Cintric and actually made a tool just for this purpose. It will track the location in the background even after the app has been quit, using only 1% battery too!
You can download the .framework file, drag it into your project and initialize with one line of code:
[CintricFind initWithApiKey:@"YOUR_API_KEY_HERE" andSecret:@"YOUR_SECRET_HERE"];
You can get an API key for free.
There are docs here: https://www.cintric.com/docs/ios
And there is a blog post explaining further here: http://www.blog.cintric.com/?p=121
You can set up monitoring location stuff in you VC as below
in viewDidLoad method do as below
CLLocationManager locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;(Accuracy according to your need)
[locationManager startUpdatingLocation];
than you have to overrite below two optional delegate methods of CLLocationManagerDelegate protocol
for iOS6+
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{}
and for iOS 2 to 6
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
in these methods you will get updated location. use it as you want. every time location updated these method get calls.
As far as I know, significant change location update is the only way to update current location when the app is running in background or not suspended(terminated) by system. when that happens, be sure to check UIApplicationLaunchOptionsLocationKey and initialise CLLocationManager to handle location change notification. If the app is running in foreground, that's simple case.
By the way, in order to let system keep updating location to your app, you must enable maps feature and background modes(location updates) for the project.
read Apple location/Map documents for more details.
What you need is geofencing. In iOS it's called "region monitoring". You can start with startMonitoringForRegion:
in the CLLocationManager guide. More detail is in the Region Monitoring Guide
In iOS, regions associated with your app are tracked at all times, including when your app is not running. If a region boundary is crossed while an app is not running, that app is relaunched into the background to handle the event. Similarly, if the app is suspended when the event occurs, it is woken up and given a short amount of time (around 10 seconds) to handle the event.