Reputation: 101
var ref = Database.database().reference().child("Essages")
var childRef = Database.database().reference().child("Essages").childByAutoId()
@IBAction func sendBtn(_ sender: Any) {
posting()
}
func posting(){
let values = ["message" : captionTextView.text] as [String : Any]
childRef.updateChildValues(values) { (error, ref) in
if error != nil {
print("error")
}else {
let = Timer.scheduledTimer(timeInterval: 90000, target: self, selector: #selector(self.onTick), userInfo: nil, repeats: false)
}
}
}
func onTick(){
childRef.removeValue()
}
If the app is open then the timer is working and it is deleting the data. But if I close the app the timer is not working and the data is not deleted. Please help me in sorting this problem. I'm trying to get feature like snapchat (deleting in 24hrs).
Upvotes: 0
Views: 112
Reputation: 612
You could try perhaps a new Firebase cloud function feature, which is I think the best and easiest option. It was in beta until couple of weeks ago but now it's fully functional.
There was a similar question on another thread here. You can also find a nice tutorial on the Firebase Blog. In general, following some good coding practices, you shouldn't be triggering this from a client. Data cleanup, and in any other form of updates should be done by the backend itself.
Upvotes: 1