Keeping iOS application running during system alert overlays and temporary interruptions

I have a Unity iOS application that needs to continue running at all times when in the foreground, even when behind a system alert overlay or during other temporary interruptions.

By default, Unity pauses an app when a system alert happens. For example, Unity will pause behind the low battery indicator or the trust this computer overlay that pops up when you plug into a new computer. This is the correct behavior for most games. However, my application needs to alert users very reliably at specific times and, ideally, show a running clock. If paused, it cannot generate an alert nor update the clock.

Unfortunately, local notifications are no help here for an alert, either. Local notifications work great when my app is in the background, but will not show when in this paused state. To iOS, the paused app is still in the foreground, and Apple does not show local notifications for apps in the foreground. And the running clock is paused while awaiting the notification, anyway.

I see that code in UnityAppController.mm pauses all Unity operations when it receives an applicationWillResignActive signal from the device. From Apple’s state transition document, applicationWillResignActive is called not just when going to the background, but also during system alert overlays and other temporary interruptions.

Instead of pausing on applicationWillResignActive, I would prefer to pause only when actually entering background state. Per the Apple docs, this would be the on a call to applicationDidEnterBackground.

My solution has been to move all of the pause code in Unity’s UnityAppController.mm from applicationWillResignActive to applicationDidEnterBackground. This appears to be working. However, I wanted to see if this might cause problems or if there might be a better way.

So, for the Unity iOS community:

  • Is the best way to keep a Unity iOS app running during system alerts and temporary interruptions to migrate the pause code from applicationWillResignActive to applicationDidEnterBackground in UnityAppController.mm? Or is there a better, easier way?
  • Are there potential issues or risks to moving Unity’s pause code to applicationDidEnterBackground?

I have been testing a build with all pause code moved to applicationsDidEnterBackground and it appears to be working. I would be curious if anyone else has tried this or if there are risks, per my original questions.

Hi @KevinCodes4Food I know it’s an old thread. But, please, can you tell us if your approach worked well?

Hi Kevin, Would love to know how this works and how you implemented it. I’m having trouble with my Unity Window disappearing when an alert pops up in a native ios app i’m working on