1. Submit bugs to enter our 5.4 Beta Sweepstakes. Read more about it here.
  2. Unity 5.4 public beta is now available for all users. Grab the build and visit the 5.4 beta forum.
  3. Missing a module? More about the new installer in 5.3 here.
  4. 4.7.1 released for Xcode 7.3 support. Thread here.

Call function when coming back from background?

Discussion in 'iOS and tvOS Development' started by jmansa, Apr 13, 2012.

  1. jmansa

    jmansa

    Joined:
    Apr 13, 2012
    Messages:
    31
    I'm trying to figure out how to call a function when my iOS application is coming back from background. I have read through som posts I can use "OnApplicationPause" but not sure how to do so when coming back from background... Can anybody help?

    Thanks in advance :)
     
  2. _Daniel_

    _Daniel_

    Joined:
    Feb 28, 2007
    Messages:
    2,165
  3. jmansa

    jmansa

    Joined:
    Apr 13, 2012
    Messages:
    31
  4. jmansa

    jmansa

    Joined:
    Apr 13, 2012
    Messages:
    31
    I have tried this:
    Code (csharp):
    1. function OnApplicationPause(pause:boolean){
    2.    game_message = true;
    3. }
    That works when the application goes into sleep... But I want to run the game_message = true; when the application wakes up again! How do I do this?

    Hooping for help :)
     
  5. _Daniel_

    _Daniel_

    Joined:
    Feb 28, 2007
    Messages:
    2,165
    Code (csharp):
    1. function OnApplicationPause (pause : boolean) {
    2.    if (pause) {
    3.       // Put code in here that you want to run when the game enters background.
    4.    }
    5.    else {
    6.       // Put code in here that you want to run when the game enters foreground.
    7.    }
    8. }
    I would also try OnApplicationFocus.