Code Wiget
Code Wiget

Reputation: 1672

NSTimer run in background - needs to fire every hour

I created an app that will send text messages through an API similar to Twilio, and I have an NSTimer that fires a function every set amount of time. The problem is that if you press the home button, it will totally stop the timing, which defeats the purpose.

I have read that it is possible to have your phone play a mute sound until closed to make sure it still runs in the background, but I can't find a resource on how to do this. Here is an example: To run NSTimer in background

If anyone has any information on how to do this, I'm sure it is very simple, and I very much appreciate the help.

Thank you.

Upvotes: 0

Views: 337

Answers (1)

Duncan C
Duncan C

Reputation: 131398

If you set up your app as a background sound playing app then yes, it is technically possible to play a "silent sound" in order to keep it active in the background, but your app will be rejected by Apple if you do this.

Apple expressly forbids what you are trying to do.

You should look at using scheduled local notifications. Those will alert the user, who can bring your app to the foreground and let it perform the desired task.

Upvotes: 3

Related Questions