On application quit on iOS

Alessandro 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 4

I'm trying to get the DateTime.now when I close a game on iOS and when I reopened, but I don't seem to be able to.

I successfully managed to get the DateTime.now when I suspend the app by using the events OnApplicationPause/OnApplicationResume. They work correctly and give me the right time.

But they do not work when you close the app.

So I tried using OnApplicationQuit to get the quit time and Start to get the start time, but they do not return the time.

What should I use on iOS to get the dateTime.Now when I exit an app?

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):

From the Unity documentation: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationQuit.html

Note: iOS applications are usually suspended and do not quit. You should tick "Exit on Suspend" in Player settings for iOS builds to cause the game to quit and not suspend, otherwise you may not see this call. If "Exit on Suspend" is not ticked then you will see calls to OnApplicationPause instead.

Could this be the issue?

I tried that but that doesn't help, it actually blocks what is currently working.

If I change to exit on suspend, when I resume it, it just restart the app, and doesn't trigger the on suspend behaviour at all.

Currently the suspend behaviour works: if I suspend the app, a datetime is saved and when resumed, datetime.now it is checked, how much time has passed is calculated and returned, converted to a float and printed as text.

But if I restart from quit, the above doesn't happen, the text box doesn't show up, which is the intended behaviour to happen if the variable that saved the datetime returns a null.

Which leads me to believe that nothing has been saved "on quit".

What I'm trying to figure out is what is the right event to use on closing an iOS app so that it saves datetime.now to the intended variable.

Works in editor, so it must be something iOS-related, not Bolt-related.

Sorted using On Focus.

All I can say is that we relay the events we get directly from Unity, no filtering on our end. So if it doesn't get triggered, it means Unity didn't send the event. Sorry about that!