App Crashes when Opening Control Center

I’ve been playing with the app lifecycle callbacks a bit, and the best workaround I could come up with is this.
When the control center is open:

  • The app continues to render. (It currently pauses the app.)
  • If the control center is closed, the app continues to run as expected.
  • If the user quits the app by pressing X in the control center, the app quits as expected.
  • If the user goes to the Home menu, the app quits as well (not expected, but might be an okay tradeoff if we need to ship with this version of Unity).

It appears that force quitting the app and going back to the Home menu, gives us the same callback, so this is the best I could do.

For reference I modified two methods in UnityAppController.mm, which now look as follows:

- (void)applicationDidEnterBackground:(UIApplication*)application
{
    ::printf("-> applicationDidEnterBackground()\n");

    if (_unityAppReady)
    {
        _wasPausedExternal = UnityIsPaused();
        if (_wasPausedExternal == false)
        {
            UnityRequestQuit();
            UnityQuitApplication(0);

            UnityWaitForFrame();
        }
    }

    _didResignActive = true;
}

// ...

- (void)applicationWillResignActive:(UIApplication*)application
{
    ::printf("-> applicationWillResignActive()\n");

    if (_unityAppReady)
    {
        UnitySetPlayerFocus(0);
    }
}

This feels super hacky, but it seems to work. @mtschoen any other ideas/pointers?

1 Like