diff --git a/ProjectClock/AlarmActivationViewController.swift b/ProjectClock/AlarmActivationViewController.swift index b81417f..23a7cde 100644 --- a/ProjectClock/AlarmActivationViewController.swift +++ b/ProjectClock/AlarmActivationViewController.swift @@ -11,11 +11,24 @@ import AVFoundation class AlarmActivationViewController: UIViewController { var timer: Timer? + var currentAlarm: Alarm? + + init?(coder: NSCoder, currentAlarm: Alarm) + { + self.currentAlarm = currentAlarm + //print(currentAlarm.wakeMethod) + super.init(coder: coder) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } override func viewDidLoad() { super.viewDidLoad() timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(AlarmActivationViewController.playSound), userInfo: nil, repeats: true) + setAlarmType() } @objc func playSound() @@ -23,4 +36,23 @@ class AlarmActivationViewController: UIViewController AudioServicesPlayAlertSound(SystemSoundID(1005)) AudioServicesPlayAlertSound(kSystemSoundID_Vibrate) } + + func setAlarmType() + { + if let alarm = currentAlarm + { + switch alarm.wakeMethod.name { + case "Walk": + walkAction() + case "Jump": + jumpAction() + case "Puzzle": + puzzleAction() + case "Smash": + print("") + default: + print("Invalid alarm type") + } + } + } } diff --git a/ProjectClock/AlarmActivator.swift b/ProjectClock/AlarmActivator.swift index acb0b42..29b81d0 100644 --- a/ProjectClock/AlarmActivator.swift +++ b/ProjectClock/AlarmActivator.swift @@ -20,6 +20,7 @@ class AlarmActivator: UITabBarController /// Timer for scheduled calls var timer: Timer? + var alarm: Alarm? override func viewDidLoad() { @@ -49,7 +50,7 @@ class AlarmActivator: UITabBarController */ @objc func check() { - NSLog("Check") + //NSLog("Check") // Get the alarm to activate let alarms = Alarms.fromLocal() @@ -62,9 +63,14 @@ class AlarmActivator: UITabBarController } alarms.localSave() - + self.alarm = alarm // Segue - NSLog(JSON.stringify(alarm)!) + //NSLog(JSON.stringify(alarm)!) performSegue(withIdentifier: "activate-alarm", sender: alarm) } + + @IBSegueAction func sendAlarm(_ coder: NSCoder) -> AlarmActivationViewController? { + return AlarmActivationViewController(coder: coder, currentAlarm: alarm!) + } + } diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index 98345b6..0b2d038 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - - + + - + @@ -14,14 +14,14 @@ - + - + - + - + - +