Files
GetGoing/ProjectClock/AlarmActivator.swift
T
2021-01-17 10:34:53 -05:00

50 lines
950 B
Swift

//
// AlarmActivator.swift
// ProjectClock
//
// Created by Hykilpikonna on 1/17/21.
//
import Foundation
/**
Class to activate alarms when the user is inside the app
Note: This will not run when app is switched to the background,
but it will run right after the user switched back to the app.
*/
class AlarmActivator
{
/// Interval in seconds
static var interval = 1.0
/// Timer for scheduled calls
var timer: Timer?
/**
Start detecting alarms
*/
func start()
{
if timer != nil { return }
timer = Timer.scheduledTimer(timeInterval: AlarmActivator.interval, 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")
}
}