I have an Alamofire function that calls an API. How do I make this function trigger every hour since the first time the function is triggered?
I currently have this function but looks like this code is work with delay of 1 hour after it's called. I need the function to be called with interval of 1 hour after the first API is called. So I called the API for the first time, and for the next one hour I just use the data that I called earlier.
func getAdds() {
addsViewModel.timer.setEventHandler {
self.addsViewModel.getAddsImage { [weak self] response, fileType in
if response == 200 {
self?.addsViewModel.filterPromotion()
self!.setupAdds(typeFile: fileType, data: self!.addsViewModel.filteredPromotion!.coverFileName!)
}else if response != 200 || self!.addsViewModel.dataPromotion[0].visible == false && self!.addsViewModel.dataPromotion[0].active == false || self!.addsViewModel.bannerAdds?.isEmpty == true {
self?.dismiss(animated: false)
}else{
self?.dismiss(animated: false)
}
}
}
addsViewModel.timer.schedule(deadline: .now() + .seconds(3600), repeating: .seconds(3600), leeway: .seconds(60))
addsViewModel.timer.activate()
}
Does anyone know how to make this work as I want?