Question

I had a project where I was using Region monitoring with a varied amount of success, for the most part it worked, but not as accurate as i hoped, but soon discovered it's not supposed to be dead accurate and this is fine, just physically testing it was difficult. Nevertheless they wanted a complete user interface overall hall done in a day. so here is what i did.

I took the old project, duplicated it and renamed it, bundle ID and all and the where ever else i think needed it to make it essentially a different project. I then created a storyboard as i was using xib files previously. And then changed the launch procedures to make it use the storyboard instead of the pre-existing xib files. all worked dandy. have the new interface and essentially the same code.

Problem...

The regions never trigger...ever, even though locations services is working as i use location services to tell me if i'm within the radius of one or not, but the fence callback API just never goes off. I then tested it on multiple devices. and finally one of them triggered...But low and behold it was the old app, it triggers fences no problem. whereas the new one does not. I can't even begin to fathom what i have done wrong that would cause this. I even use the api did fail and did succeed methods and it says the fences register no problem.

another vexing issue is, if I use GPX files to simulate location, the fences trigger in code...Frustrating stuff I must say.

Any suggestions? will provide code examples if needed.

Was it helpful?

Solution

Ok there are a few things here that I can think of given the QA details:

1- Ensure that when you copied the project, that you have also duplicated the .plist correctly and that the "location updates" in background mode has been enabled.

2- When I was testing didEnterRegion and didExitRegion, I found that there were not always exact whether driving or walking. After looking into it, I gather region monitoring has an algorithm that "ensures" that you have actually crossed the boundary of the region before triggering the didEnterRegion and didExitRegion. And as such, if you radius is 100 meters and you walk 101 meters from the center in one direction and assume it will trigger didExitRegion, it will likely not happen. You would have to sometimes walk or drive another x meters for it to launch and same for didEnterRegion. My recommendation here is to ensure you always go significantly beyound the radius in your code.

Now this becomes more complicated, if you are inside the region and you cross out the 100 meters and come back in. it is likely that you will not get a trigger because you never crossed out (from a region monitoring stand point) in the first place to cross back in!

This is not a problem with GPX because you are forcing the crossing out (exiting the region) so you are not allowing the device to apply its algorithm to safely ensure you have crossed out.

3- Make sure to implement:

-(void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region

Put some NSLogs to determine state when launching. This should help focus the problem as well as it should trigger rightaway to let you know if you are in or our out of the region (even without crossing). If this does not trigger, there are bigger problems.

4- Last, CLRegion is deprecated in iOS7. You need to use CLCircularRegion. And initiate the region with the method:

initWithCenter:(CLLocationCoordinate2D)center radius:(CLLocationDistance)radius identifier:(NSString *)identifier

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top