From 4d2f363f8ae8048d0a8ef49953473a1e32ee3277 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 27 Jan 2021 20:28:31 -0500 Subject: [PATCH] [F] Fix longer alarm sounds cutting off problem --- .../AlarmActivationViewController.swift | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ProjectClock/AlarmActivationViewController.swift b/ProjectClock/AlarmActivationViewController.swift index 1028055..85e0d1e 100644 --- a/ProjectClock/AlarmActivationViewController.swift +++ b/ProjectClock/AlarmActivationViewController.swift @@ -17,7 +17,6 @@ var alarmStarted = false */ class AlarmActivationViewController: EndEditingOnReturn { - var timer: Timer? var currentAlarm: Alarm // Puzzle outlets @@ -37,6 +36,8 @@ class AlarmActivationViewController: EndEditingOnReturn @IBOutlet weak var timeLabel: UILabel! @IBOutlet weak var dateLabel: UILabel! + var solved = false + /** Constructor to receive alarm data from segue */ @@ -68,7 +69,8 @@ class AlarmActivationViewController: EndEditingOnReturn shakeView.hide() // Play sound - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(AlarmActivationViewController.playSound), userInfo: nil, repeats: true) + playSound() + vibrate() // Run alarm runAlarm() @@ -80,10 +82,18 @@ class AlarmActivationViewController: EndEditingOnReturn /** Play alarm sound */ - @objc func playSound() + func playSound() { - AudioServicesPlayAlertSound(currentAlarm.alarmTone) - AudioServicesPlayAlertSound(kSystemSoundID_Vibrate) + AudioServicesPlayAlertSoundWithCompletion(currentAlarm.alarmTone) { + if alarmStarted { self.playSound() } + } + } + + func vibrate() + { + AudioServicesPlayAlertSoundWithCompletion(kSystemSoundID_Vibrate) { + if alarmStarted { self.vibrate() } + } } /** @@ -175,9 +185,8 @@ class AlarmActivationViewController: EndEditingOnReturn */ func endAlarm() { - timer?.invalidate() + alarmStarted = false print("Alarm solved") dismiss(animated: true, completion: nil) - alarmStarted = false } }