Skip to content

Commit

Permalink
Fix leaky announcement timer (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Sudekum authored Sep 19, 2017
1 parent 16312c8 commit d1abeb1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions MapboxNavigation/RouteVoiceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
let routeStepFormatter = RouteStepFormatter()
var recentlyAnnouncedRouteStep: RouteStep?
var fallbackText: String!
var announcementTimer: Timer!
var announcementTimer: Timer?

/**
A boolean value indicating whether instructions should be announced by voice or not.
Expand Down Expand Up @@ -80,6 +80,7 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
deinit {
suspendNotifications()
speechSynth.stopSpeaking(at: .word)
resetAnnouncementTimer()
}

func resumeNotifications() {
Expand Down Expand Up @@ -148,12 +149,13 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
}

func startAnnouncementTimer() {
announcementTimer?.invalidate()
announcementTimer = Timer.scheduledTimer(timeInterval: bufferBetweenAnnouncements, target: self, selector: #selector(resetAnnouncementTimer), userInfo: nil, repeats: false)
}

func resetAnnouncementTimer() {
announcementTimer?.invalidate()
recentlyAnnouncedRouteStep = nil
announcementTimer.invalidate()
}

open func alertLevelDidChange(notification: NSNotification) {
Expand Down

0 comments on commit d1abeb1

Please sign in to comment.