From 879689a10abf61ef3c98b46a8194b9266a8cd004 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 17 Jan 2021 10:33:29 -0500 Subject: [PATCH] [+] Start alarm detector on app start --- ProjectClock/AlarmActivator.swift | 4 ++-- ProjectClock/AppDelegate.swift | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ProjectClock/AlarmActivator.swift b/ProjectClock/AlarmActivator.swift index 65dcf59..449731e 100644 --- a/ProjectClock/AlarmActivator.swift +++ b/ProjectClock/AlarmActivator.swift @@ -13,7 +13,7 @@ import Foundation class AlarmActivator { /// Interval in seconds - static var interval = 1 + static var interval = 1.0 /// Timer for scheduled calls var timer: Timer? @@ -24,7 +24,7 @@ class AlarmActivator func start() { if timer != nil { return } - timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(AlarmActivator.check), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer(timeInterval: AlarmActivator.interval, target: self, selector: #selector(AlarmActivator.check), userInfo: nil, repeats: true) } /** diff --git a/ProjectClock/AppDelegate.swift b/ProjectClock/AppDelegate.swift index 7eed2de..1bcaf9a 100644 --- a/ProjectClock/AppDelegate.swift +++ b/ProjectClock/AppDelegate.swift @@ -8,29 +8,31 @@ import UIKit @main -class AppDelegate: UIResponder, UIApplicationDelegate { - - - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { +class AppDelegate: UIResponder, UIApplicationDelegate +{ + var alarmActivator: AlarmActivator! + + func application(_ app: UIApplication, didFinishLaunchingWithOptions op: [UIApplication.LaunchOptionsKey: Any]?) -> Bool + { // Override point for customization after application launch. + alarmActivator = AlarmActivator() + alarmActivator.start() + return true } - // MARK: UISceneSession Lifecycle - - func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + func application(_ app: UIApplication, configurationForConnecting session: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration + { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. - return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + return UISceneConfiguration(name: "Default Configuration", sessionRole: session.role) } - func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + func application(_ app: UIApplication, didDiscardSceneSessions sessions: Set) + { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } - - }