Fix: closing of sessions weren't being tracked sometimes

In some situations, `applicationDidEnterBackground:` wasn't executed.
We've switched to `applicationWillResignActive:` and also moved the crucial code to the beginning of the method.

Signed-off-by: Miguel M. Almeida <miguelcma@CMA-Retina.local>