diff --git a/apps/ios/GuideDogs/Code/App/Settings/SettingsContext.swift b/apps/ios/GuideDogs/Code/App/Settings/SettingsContext.swift index f6d603e..8f4e54a 100644 --- a/apps/ios/GuideDogs/Code/App/Settings/SettingsContext.swift +++ b/apps/ios/GuideDogs/Code/App/Settings/SettingsContext.swift @@ -380,6 +380,8 @@ class SettingsContext { } set { userDefaults.set(newValue, forKey: Keys.leaveImmediateVicinityDistance) + // Ensure leave is always 15m greater than enter + userDefaults.set(max(newValue - 15.0, 0.0), forKey: Keys.enterImmediateVicinityDistance) } } @@ -389,6 +391,8 @@ class SettingsContext { } set { userDefaults.set(newValue, forKey: Keys.enterImmediateVicinityDistance) + // Ensure leave is always 15m greater than enter + userDefaults.set(newValue + 15.0, forKey: Keys.leaveImmediateVicinityDistance) } } } diff --git a/apps/ios/GuideDogs/Code/Behaviors/Default/BeaconCalloutGenerator.swift b/apps/ios/GuideDogs/Code/Behaviors/Default/BeaconCalloutGenerator.swift index 2d16cac..f381ddd 100644 --- a/apps/ios/GuideDogs/Code/Behaviors/Default/BeaconCalloutGenerator.swift +++ b/apps/ios/GuideDogs/Code/Behaviors/Default/BeaconCalloutGenerator.swift @@ -237,7 +237,7 @@ class BeaconCalloutGenerator: AutomaticGenerator, ManualGenerator { } let causedAudioDisabled = event.beaconWasEnabled && !event.beaconIsEnabled - guard let destinations = getCalloutsForBeacon(nearby: event.location, origin: .beaconGeofence, causedAudioDisable: causedAudioDisabled) else { + guard let destinations = getCalloutsForBeacon(nearby: event.location, origin: .beaconGeofence, causedAudioDisable: causedAudioDisabled, didExitGeofence: !event.didEnter) else { return nil } @@ -261,7 +261,7 @@ class BeaconCalloutGenerator: AutomaticGenerator, ManualGenerator { return group } - private func getCalloutsForBeacon(nearby location: CLLocation, origin: CalloutOrigin, causedAudioDisable: Bool = false) -> [DestinationCallout]? { + private func getCalloutsForBeacon(nearby location: CLLocation, origin: CalloutOrigin, causedAudioDisable: Bool = false, didExitGeofence: Bool = false) -> [DestinationCallout]? { // Check if destination callouts are enabled guard settings.destinationSenseEnabled else { GDLogAutoCalloutInfo("Skipping beacon auto callouts. Beacon callouts are not enabled.") @@ -273,6 +273,16 @@ class BeaconCalloutGenerator: AutomaticGenerator, ManualGenerator { return nil } + /// Only play "Beacon within x units" callouts when entering (not exitinhg) beacon geofence. For large values of + /// enterImmediateVicinityDistance, when exiting a geofence, the auto callouts will immediately announce a + /// "Beacon: x units" value greater than the geofence radius, and we don't want to mistakenly imply we're + /// moving towards the beacon. + if origin == .beaconGeofence { + guard !didExitGeofence else { + return nil + } + } + // If the callout is not coming from .auto, there are no additional checks to make if origin == .auto, let destination = spatialData.destinationManager.destination { // Check the update filter (if this callout is coming from auto callouts)