The other poster's code would let you avoid triggering the sound from playing the same sound multiple times at once. I gather that instead you only want the sound to be played once when you reach a given proximity.
You can adapt Armand's code to do that. Rename the boolean to be "hasPlayed"
Then make your didRange call look something like this:
void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
//Do whatever else you need to do to handle the ranging call
if (!self.hasPlayed)
{
[self playSound];
self.hasPlayed = true;
}
}
Get rid of the custom code in audioPlayerDidFinishPlaying:successfully:
that clears the flag.
If you want to keep track of multiple beacons, and want to play your sound when the user enters the proximity of a different beacon, it's a little more complicated.
If you use the same UUID but a different major value, say, then instead of a boolean, save a unique id of some sort (like the major value) for the last beacon who's sound you've played. Let's call the property lastBeaconRanged. Then when you range a beacon, see if the ranged beacon's ID matches the one who's sound you played last. If not, play the sound and save this beacon's ID into your lastBeaconRanged property.