Hey everyone!
I'm trying to develop an app that would need to send periodic notifications (every 20 minutes, for instance) to the user even when the app is not running (but only when the phone is being used). I've been reading through the prior comments and all about not being able to have a timer run in the background in the way I need it to, but I wanted to ask if there's any way around this, or is there truly no way?
If there is no way to do this, I was just now considering another workaround, where I could try getting the time they open their phone, and from there, I schedule local notification for every 20 minutes or so for the entire day, and they keep sending until the phone is turned off, when the rest of the scheduled local notifications are cancelled. Is this possible?
I would also appreciate any other suggests/workarounds for this. Happy to provide any additional details needed!
Thanks!
First, you should understand that when your app is not running, and in most cases when the screen is off, it is not possible to run code in your app, whether be running timers, checking status of this and that, and making decisions of whether to send notifications or not.
You may want to read about iOS Background Execution Limits to understand limitations of app NOT active and running in the foreground.
The closest I can think of to solve your problem is by scheduling a notification locally from your app to fire every 20 minutes, while setting the Interruption level of the notifications to Passive
The .passive
setting for notifications will avoid lighting up the screen or playing a sound when the notification arrives if the screen is off (which is what I suppose you mean by "phone being turned off"), even though the notifications will continue firing.
The side effect of this setting is (I don't know if it is desired or not) that the notifications will also not interrupt the user when they are using another app, or they are in a focus mode that limits interruptions.
This may or may not be suitable for your use case, but it is about as close as you can get to your desired behavior considering the limitations of apps executing in the background, or implementing a workaround that might go against the App Review Guidelines
Argun Tekant / DTS Engineer / Core Technologies