2

I have an alert controller which has an option that should fire a timer. After that time has passed, no matter if the app is in background or not, the action should execute. I have searched a lot about it and this is what a I've found so far:

  • I tried using BGTaskScheduler, but it doesn't work as I expected. You can set the minimum time that should pass so the action fires after that. The problem is that is actually the system who decides when to fire that action and you can't determinate when it is going to do it (More information: iOS 13 - Using BGTaskScheduler doesn't work all the time)
  • The other option that I have seen is using a normal timer. The problem is that I think the maximum time that a timer can run is 3 minutes in background. I need to run it for 30 minutes, 2 hours and 1 day.

Is there a way to achieve that goal?

Edward Pizzurro
  • 575
  • 4
  • 15
  • 1
    You cannot fire a timer if the app is the background. And what if the app goes into the background and is terminated? The whole idea makes no sense. What is it that you _really_ want to do? – matt Apr 30 '21 at 03:44
  • So my app is always listening even if it's in the background. The idea is to deactivate that listening for a period of time (30 minutes, 2 hours and 1 day). When I deactivate it, I am in the app and the timer should start running. What I want is that timer to run even if my app goes into the background and then do some action once the 30 minutes has passed. – Edward Pizzurro Apr 30 '21 at 14:33
  • “So my app is always listening even if it's in the background.” No it isn’t. Your app stops running when it’s in the background. It is suspended, frozen. And it can be terminated. – matt Apr 30 '21 at 14:41
  • I meant that I developed that way, so the app can listen even if it's in the background. That's the functionality that is doing right now. What I want to do is to deactivate that functionality for a period of time and then do some action even if the app is in background. What I was wondering is that if there is a way to do it or i cannot simply use a timer for 30 minutes in the background. – Edward Pizzurro Apr 30 '21 at 14:44

0 Answers0