Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hellobard · Jan 13, 2013 at 07:19 PM · iosonapplicationpause

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jogo13 · Jan 13, 2013 at 10:42 PM 0
Share

There is an option called 'exit on suspend' in the iOS player settings. You'll need to make sure it's unchecked.

avatar image hellobard · Jan 13, 2013 at 11:08 PM 0
Share

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.

avatar image Fattie · May 19, 2013 at 09:50 AM 0
Share

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.}

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · May 19, 2013 at 09:52 AM 0
Share

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.

avatar image
0

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"); }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by protar123123456678A · Jul 13, 2018 at 08:01 PM

This is great indeed,

With Regards, Protar. Plex App Tutuapp App Vidmate App

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges