- Home /
MonoBehaviour.OnApplicationQuit() can not be called on Android or iOS devices
Hello,
I found that The OnApplicationQuit() cannot be called when the app is closed by Android/iOS.(it's good on unity editor) Then cause to my "player.stop" event can not be sent when user close the app. (player.stop trigger in OnApplicationQuit()).
There are the same issues online, but no suitable solution. The most solution is that replace OnApplicationQuit() by OnApplicationPause(), but it is not fit for the player.stop event.
I also found a note in OnApplicationQuit() introduction, “Note that 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.” https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationQuit.html
But the "Exit on Suspend" has Obsoleted. https://docs.unity3d.com/ScriptReference/PlayerSettings.iOS-exitOnSuspend.html
Is there a way can guaranteed OnApplicationQuit() be called when closing, or there is any other solution?
Thank you very much!! Song
Answer by hexagonius · Oct 20, 2018 at 09:43 AM
This answer has a good answer to your question:
https://answers.unity.com/questions/824790/help-with-onapplicationquit-android.html
bottom line, whatever you need to do, make it work using OnApplicationPause