How to know when my game is in background?

Hi guys,

I’m working in an iOS game with Unity and I need to know when the player has pressed the Home button a.k.a when the game just entered background.

A little research show me that I may need to use OnApplicationPause and/or OnApplicationFocus. Do you guys know what this is?

The reason is because a schedule local notification I want create ONLY when the player has the game in background.

Thanks!

OnApplicationFocus is what you’re going to want to use, which works on all supported platforms I believe.

OnApplicationFocus() is a override-able method, meaning that Unity has left the implementation of this method up to you, such as

void Start()

or

void Awake()

So, in your script you would do:

void OnApplicationFocus( bool focus )
{
    if( focus )
    {
        // Put your scheduled local notification here
    }
}