Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>We've run into a similar challenge. But there's a problem with either solution: there's a 'bug' in how Apple handles ranging and proximity, and you'll get random toggling and didExitRegion calls. </p> <p>See here:</p> <p><a href="http://beekn.net/2013/11/ibeacon-tutorial-dealing-with-errors/" rel="nofollow">http://beekn.net/2013/11/ibeacon-tutorial-dealing-with-errors/</a></p> <p>Your app will call a didExitRegion seemingly at random, clearly a bug, because Location Services can actually shut down entirely for a second or so.</p> <p>We handled the viewController idea by stopping ranging once the viewController is pushed and then restarting it once the user closes the viewController.</p> <ol> <li>After: [self performSegueWithIdentifier:@"mainToContent" sender:self];</li> </ol> <p>Add: </p> <p>[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];</p> <ol> <li>In order to restart ranging once the user closes the viewController, add:</li> </ol> <p>// ViewWillAppear restarts stopRanging when OutsideViewController is pushed - (void)viewWillAppear:(BOOL)animated { [self.locationManager startRangingBeaconsInRegion:self.beaconRegion]; }</p> <p>NOTE: If you want to close the viewController automatically based on a region change, you'll have the problem of rapid push and pull: you'll push a viewController and then it will quickly close, open, close....the problem isn't the code, it's that the Apple API can't always make up its mind what region it's in.</p> <p>POSSIBLE SOLUTION? The "hack" might be to add a counter: what we've found is that you'll hold your phone close to a beacon and it will quickly toggle between near/immediate even though you are NOT moving your phone and the beacon signal isn't actually changing. It's an Apple "bug"! But it will only do this once or twice.</p> <p>One option is to add a counter: the equivalent of "only if you've detected a region change three or four times should you trigger the event"</p> <p>The other option is to add a time: "only trigger an event based on a region change if its been 4 seconds that the region has changed"</p> <p>Again - the problem isn't that you'll get sudden toggles (pushing a VC or pulling it off the stack) because you're 'between zones' - the problem is:</p> <p>A. Apple API can't always properly tell whether you're immediate/near/far and will suddenly change its mind</p> <p>B. Apple will sometimes shut off location services seemingly randomly and for less than a second, forcing your app to re-enter a region and start ranging again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload