- Home /
Call a Function When App Exits
I'm working on an iOS game right now, and I need a function to be called whenever the app is sent to the background, or exited. Is there something that can do this?
Answer by Meltdown · Sep 18, 2011 at 06:31 PM
You can call something using OnApplicationQuit
Haha wow, that simple huh? I don't know how I missed it. Thanks!
Answer by TeddyDief · Sep 25, 2012 at 09:20 AM
OnApplicationPause() is the one you want for iOS when you send the app to background!
Answer by BerggreenDK · Sep 18, 2011 at 06:32 PM
yes, check this quick search for events "onApplication"
I think you might find them interesting: http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=onapplication
Great, just note that the last one: Application.CancelQuit doesnt work on iOS.
Unfortunately, after trying it out, these functions all work in the Unity Editor, but not on the actual device. The device doesn't detect a focus change or quit, or at least it doesn't react the same way the Unity Editor does.
Answer by Dvabhs · Jul 18, 2014 at 07:05 AM
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.
Your answer
Follow this Question
Related Questions
Application Crashes On Launch - How To Fix? 0 Answers
Run in background for iOS 3 Answers
Background Networking Activity and Unity Run Loop 0 Answers
iOS Background Thread Problem 0 Answers
iPhone exits app when game ends? 1 Answer