- Home /
Closing and then reopening app iOS
Hi,
I am trying to make a command run right when a user returns from my app when it has been closed / suspended.
I have found the function OnApplicationPause in the Unity docs, but this does not seem to work for me.
function OnApplicationPause (pauseState : boolean) {
CameraDevice.Instance.SetFlashTorchMode(true);
}
I am having trouble finding information about this on the forum too. Has anyone made a return from suspension menu or something that can point me in the right direction?
There is an option called 'exit on suspend' in the iOS player settings. You'll need to make sure it's unchecked.
thanks, but that is not what i am after. my app is multitasking just fine. what i want to do is run a command once the app returns from being suspended.
I'm confused here, to use OnApplicationPause it's very simply:
function OnApplicationPause(p:boolean)
{
if ( p ) the app has JUST PAUSED
else the app has JUST RESU$$anonymous$$ED
}
note that you must have this in a dontdestroyonload game object.
this is a simple thing you have to do in every iPhone-Unity app ... completely SOP.
Looking at your code fragment, it appears to simply be the case, that you are using it incorrectly. You must do the "if ..." part using pauseState.
{Graham, I was searching here to see if Unity offers a distinction between applicationWillResignActive and applicationDidEnterBackground ...
applicationWillResignActive ... that's when you doubleclick the iOS plastic button and the app moves "up"
applicationDidEnterBackground ... that's when you then click the iOS plastic button and the app goes away with an iOS inzoom animaton, and when that inzoom animation is complete, you then get applicationDidEnterBackground
(if the user directly clicks the plastic button once, you get both of those in that order.)
.. however I believe in Unity there is only OnApplicationPause(p:boolean) which I believe is triggered at applicationWillResignActive -- which is fine.}
Answer by Graham-Dunnett · Jan 14, 2013 at 11:41 AM
Maybe look at the code on AppController.mm. iOS sends to this code messages to tell it what's happening. There is an applicationDidResignActive and applicationDidBecomeActive. The code inside applicationDidBecomeActive suggests that a call is made into UnityPause(). Internally that does call into OnApplicationPause. So check that you get the callback and "-> applicationDidBecomeActive()\n" gets printed.
Just to repeat myself, I believe you are answering a "more complicated question than the OP asked"
To watch an iphone app go in or out, simply do this
function OnApplicationPause(p:boolean)
{
if ( p ) the app has JUST PAUSED
else the app has JUST RESU$$anonymous$$ED
}
it's very simple (like everything in Unity, yay!) and you do it in every iphone app in unity.
In the OP's example here the OP simply typed it out wrong.
Answer by hellobard · Jan 14, 2013 at 08:42 PM
Fantastic, that worked! Thank you so much!
I just added a UnitySendMessage command to my AppController.mm file in my Xcode build: // For iOS 4 // Callback order: // applicationWillEnterForeground() // applicationDidBecomeActive() - (void)applicationWillEnterForeground:(UIApplication *)application { UnitySendMessage("Button", "BackFromApp", ""); printf_console("-> applicationWillEnterForeground()\n"); }
Answer by protar123123456678A · Jul 13, 2018 at 08:01 PM
This is great indeed,
With Regards, Protar. Plex App Tutuapp App Vidmate App
Your answer
![](https://koobas.hobune.stream/wayback/20220613090902im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Send a Pause RPC on OnApplicationPause 1 Answer
What event gets called on resuming a game on mobile? 1 Answer
On iOS Start() getting called when app resumes 0 Answers
Render 1 more frame after OnApplicationPause on iOS 6 Answers
Is there a way to pause the game before it goes to the background? 0 Answers