[+] Start alarm detector on app start

This commit is contained in:
Hykilpikonna
2021-01-17 10:33:29 -05:00
parent 30756d32aa
commit 879689a10a
2 changed files with 16 additions and 14 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ import Foundation
class AlarmActivator class AlarmActivator
{ {
/// Interval in seconds /// Interval in seconds
static var interval = 1 static var interval = 1.0
/// Timer for scheduled calls /// Timer for scheduled calls
var timer: Timer? var timer: Timer?
@@ -24,7 +24,7 @@ class AlarmActivator
func start() func start()
{ {
if timer != nil { return } 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)
} }
/** /**
+14 -12
View File
@@ -8,29 +8,31 @@
import UIKit import UIKit
@main @main
class AppDelegate: UIResponder, UIApplicationDelegate { class AppDelegate: UIResponder, UIApplicationDelegate
{
var alarmActivator: AlarmActivator!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ app: UIApplication, didFinishLaunchingWithOptions op: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Override point for customization after application launch. // Override point for customization after application launch.
alarmActivator = AlarmActivator()
alarmActivator.start()
return true return true
} }
// MARK: UISceneSession Lifecycle func application(_ app: UIApplication, configurationForConnecting session: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
{
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created. // Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with. // 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<UISceneSession>) { func application(_ app: UIApplication, didDiscardSceneSessions sessions: Set<UISceneSession>)
{
// Called when the user discards a scene session. // 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. // 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. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
} }
} }