how to perform action at selected time intervel??even when the app is not open.?

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()

}


when i closed the app its not executing this function pleaase help me in sorting this problem....

Replies

Before terminating the app completely just start AVAudioPlayer with a blank audio, and set AVAudioPlayer numberofLoops = -1, so that it will repeat again and again. and then You can execute any fuction at any time, if the app is completely terminated also.

This is really bad advice. Notwithstanding the App Review implications (it’ll only work if you adopt the

audio
background mode, and App Review has strict guidance on how that can be used; see clause 2.5.4 of the App Store Review Guidelines), it has major technical drawbacks, not least of which is that it will seriously impact on battery life.

@srivathsav, iOS has no general-purpose mechanism for an app to run indefinitely in the background. Rather, there are a bunch of special-purpose mechanisms that are tied to specific technologies or specific user scenarios. If you can explain more about what you’re app is doing we should be able to offer further suggestions.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"