[+] Create AlarmDetector
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user