diff --git a/ProjectClock.xcodeproj/project.pbxproj b/ProjectClock.xcodeproj/project.pbxproj index 7bd502e..6ce5cd7 100644 --- a/ProjectClock.xcodeproj/project.pbxproj +++ b/ProjectClock.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 4F8A607125A9160400D88DC3 /* AddAlarmViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8A607025A9160400D88DC3 /* AddAlarmViewController.swift */; }; 4F98955225A9260400F51321 /* Net.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F98955125A9260400F51321 /* Net.swift */; }; 4FA419AF25AF93EC004CE0FC /* AlarmViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA419AE25AF93EC004CE0FC /* AlarmViewController.swift */; }; + 4FD642D325B48C380069171E /* AlarmActivator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD642D225B48C380069171E /* AlarmActivator.swift */; }; 4FF0683F25A5F18700304E6B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF0683E25A5F18700304E6B /* AppDelegate.swift */; }; 4FF0684125A5F18700304E6B /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF0684025A5F18700304E6B /* SceneDelegate.swift */; }; 4FF0684325A5F18700304E6B /* AccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF0684225A5F18700304E6B /* AccountViewController.swift */; }; @@ -27,6 +28,7 @@ 4F8A607025A9160400D88DC3 /* AddAlarmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAlarmViewController.swift; sourceTree = ""; }; 4F98955125A9260400F51321 /* Net.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Net.swift; sourceTree = ""; }; 4FA419AE25AF93EC004CE0FC /* AlarmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmViewController.swift; sourceTree = ""; }; + 4FD642D225B48C380069171E /* AlarmActivator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmActivator.swift; sourceTree = ""; }; 4FF0683B25A5F18700304E6B /* ProjectClock.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ProjectClock.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4FF0683E25A5F18700304E6B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 4FF0684025A5F18700304E6B /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -88,6 +90,7 @@ 7C5DAE9B25AF812200E44C52 /* clock.png */, 4F509BD125AE22D100726227 /* Models.swift */, 7C83963825AF68980027A94C /* TestingViewController.swift */, + 4FD642D225B48C380069171E /* AlarmActivator.swift */, ); path = ProjectClock; sourceTree = ""; @@ -179,6 +182,7 @@ 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */, 4FF0684325A5F18700304E6B /* AccountViewController.swift in Sources */, 4FF0683F25A5F18700304E6B /* AppDelegate.swift in Sources */, + 4FD642D325B48C380069171E /* AlarmActivator.swift in Sources */, 4FF0684125A5F18700304E6B /* SceneDelegate.swift in Sources */, 4FA419AF25AF93EC004CE0FC /* AlarmViewController.swift in Sources */, 4F509BD225AE22D100726227 /* Models.swift in Sources */, diff --git a/ProjectClock/AlarmActivator.swift b/ProjectClock/AlarmActivator.swift new file mode 100644 index 0000000..65dcf59 --- /dev/null +++ b/ProjectClock/AlarmActivator.swift @@ -0,0 +1,46 @@ +// +// AlarmActivator.swift +// ProjectClock +// +// Created by Hykilpikonna on 1/17/21. +// + +import Foundation + +/** + Class to activate alarms when the user is inside the app + */ +class AlarmActivator +{ + /// Interval in seconds + static var interval = 1 + + /// Timer for scheduled calls + var timer: Timer? + + /** + Start detecting alarms + */ + func start() + { + if timer != nil { return } + timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(AlarmActivator.check), userInfo: nil, repeats: true) + } + + /** + Stop detecting alarms + */ + func stop() + { + timer?.invalidate() + timer = nil + } + + /** + Check alarm + */ + @objc func check() + { + NSLog("Check") + } +}