Timers.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // Timers.swift
  3. // LoopFollow
  4. //
  5. // Created by Jon Fawcett on 9/3/20.
  6. // Copyright © 2020 Jon Fawcett. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. extension MainViewController {
  11. // Runs a 60 second timer when an alarm is snoozed
  12. // Prevents the alarm from triggering again while saving the snooze time to settings
  13. // End function needs nothing done
  14. func startGraphNowTimer(time: TimeInterval = 60) {
  15. graphNowTimer = Timer.scheduledTimer(timeInterval: time,
  16. target: self,
  17. selector: #selector(MainViewController.graphNowTimerDidEnd(_:)),
  18. userInfo: nil,
  19. repeats: true)
  20. }
  21. @objc func graphNowTimerDidEnd(_ timer:Timer) {
  22. createVerticalLines()
  23. }
  24. // Runs a 60 second timer when an alarm is snoozed
  25. // Prevents the alarm from triggering again while saving the snooze time to settings
  26. // End function needs nothing done
  27. func startCheckAlarmTimer(time: TimeInterval = 60) {
  28. checkAlarmTimer = Timer.scheduledTimer(timeInterval: time,
  29. target: self,
  30. selector: #selector(MainViewController.checkAlarmTimerDidEnd(_:)),
  31. userInfo: nil,
  32. repeats: false)
  33. }
  34. @objc func checkAlarmTimerDidEnd(_ timer:Timer) {
  35. }
  36. // Cancel and reset the playing alarm if it has not been snoozed after 4 min 50 seconds.
  37. // This allows the next BG reading to either start the timer going or not fire if the situation has been resolved
  38. func startAlarmPlayingTimer(time: TimeInterval = 290) {
  39. let alarmPlayingTimer = Timer.scheduledTimer(timeInterval: time,
  40. target: self,
  41. selector: #selector(MainViewController.alarmPlayingTimerDidEnd(_:)),
  42. userInfo: nil,
  43. repeats: false)
  44. }
  45. @objc func alarmPlayingTimerDidEnd(_ timer:Timer) {
  46. if AlarmSound.isPlaying {
  47. stopAlarmAtNextReading()
  48. }
  49. }
  50. }