Skip to content

Commit 71fd5ca

Browse files
Fixes route voice controller when no route progress is given.
1 parent e16c3b6 commit 71fd5ca

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

MapboxNavigation/RouteVoiceController.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate {
177177
@objc open func didPassSpokenInstructionPoint(notification: NSNotification) {
178178
guard !NavigationSettings.shared.voiceMuted else { return }
179179

180-
routeProgress = notification.userInfo![RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress
180+
routeProgress = notification.userInfo?[RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress
181181
assert(routeProgress != nil, "routeProgress should not be nil.")
182182

183183
guard let instruction = routeProgress?.currentLegProgress.currentStepProgress.currentSpokenInstruction else { return }
@@ -194,7 +194,10 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate {
194194
- parameter locale: The `Locale` used to create the voice read aloud the given instruction. If `nil` the `Locale.preferredLocalLanguageCountryCode` is used for creating the voice.
195195
*/
196196
open func speak(_ instruction: SpokenInstruction, with locale: Locale?) {
197-
assert(routeProgress != nil, "routeProgress should not be nil.")
197+
guard let routeProgress else {
198+
assertionFailure("routeProgress should not be nil.")
199+
return
200+
}
198201

199202
if speechSynth.isSpeaking, let lastSpokenInstruction = lastSpokenInstruction {
200203
voiceControllerDelegate?.voiceController?(self, didInterrupt: lastSpokenInstruction, with: instruction)
@@ -213,10 +216,10 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate {
213216
utterance!.voice = AVSpeechSynthesisVoice(identifier: AVSpeechSynthesisVoiceIdentifierAlex)
214217
}
215218

216-
let modifiedInstruction = voiceControllerDelegate?.voiceController?(self, willSpeak: instruction, routeProgress: routeProgress!) ?? instruction
219+
let modifiedInstruction = voiceControllerDelegate?.voiceController?(self, willSpeak: instruction, routeProgress: routeProgress) ?? instruction
217220

218221
if #available(iOS 10.0, *), utterance?.voice == nil {
219-
utterance = AVSpeechUtterance(attributedString: modifiedInstruction.attributedText(for: routeProgress!.currentLegProgress))
222+
utterance = AVSpeechUtterance(attributedString: modifiedInstruction.attributedText(for: routeProgress.currentLegProgress))
220223
} else {
221224
utterance = AVSpeechUtterance(string: modifiedInstruction.text)
222225
}

0 commit comments

Comments
 (0)