Skip navigation
Currently Being Moderated

How to exit your applications for AIR for iOS in ActionScript 3

Apr 17, 2012 9:36 AM

Hi everybody,

 

I have created a game for iOS. I wanted to terminate the application once the person presses the back button within the iPhone. Does anyone know how to achieve that?

 

I have searched and they only have the command for the Android using this method :

 

if(Capabilities.cpuArchitecture=="ARM"){

 

NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);

 

}

 

function handleDeactivate(event:Event):void

 

    {

 

    NativeApplication.nativeApplication.exit();

 

    }

 

How about iOS devices?

 

Thanks!

 
Replies
  • Currently Being Moderated
    Apr 18, 2012 7:53 AM   in reply to clavin007

    Hmmm, can you capture the back button's press? I don't know how if you can... are you just trying to get the app to actually close, and not suspend when the button is clicked? If that's the case you need to edit the app's xml and add the key like so:

     

    I copied the whole iPhone tag from the XML:

     

    <iPhone>

        <InfoAdditions>

         

          <![CDATA[<key>UIDeviceFamily</key><array><string>2</string></array><k ey>UIApplicationExitsOnSuspend</key><true/>]]>

        </InfoAdditions>

        <requestedDisplayResolution>standard</requestedDisplayResolution>

      </iPhone>

     

     

    Specifically, you just want to add:

    <key>UIApplicationExitsOnSuspend</key><true/>

     

    To the CDATA...

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 18, 2012 7:58 AM   in reply to dmeN

    I don't believe a programattic way exists to exit the app on iOS. In fact that's why you tend to get horrified when you double-apple button press and see 914 apps all running at the same time.

     

    iOS has no "back" button. I presume you mean the home button or a button in your app that you create. Androids have the back button.

     

    What the XML above will do is as soon as your user presses the home button your app will exit from memory which is a good solution.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 9:12 AM   in reply to clavin007

    Sorry i might be way off the mark, I haven't done any mobile application programming in AS I tend to do it natively.

     

    but i assume you use NativeApplication for your launch point, and then nativeApplication.exit should exit the app. easy enough to link to one of you own buttons.

     

    as for the home button i found this on the net

     

    import flash.events.Event;

    addEventListener
    (Event.ACTIVATE, activateListener);
    addEventListener
    (Event.DEACTIVATE, deactivateListener);

    private function activateListener(e:Event):void{
           
    //do something when awakened

    }


    private function deactivateListener(e:Event):void{
           
    //do something when home button is pressed.

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 9:23 AM   in reply to clavin007

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/desktop/NativeApplication.html#exit()

     

    NativeApplication's exit() method is not supported in iOS. You did mention AIR for iOS in the title so you should note that.

     

    The best you can do is use that key value pair of UIApplicationExitsOnSuspend to exit the app when the home button is pressed.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 1:14 PM   in reply to sinious

    >>I don't believe a programattic way exists to exit the app on iOS. In fact that's why you tend to get horrified when you double-apple button press and see 914 apps all running at the same time.

     

    This is exactly what the XML I mentioned does - it actually closes the app when you press the Home button, and prevents it from appearing in the Fast App Switcher Dock that lists all the running apps when you double-click Home.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 10, 2013 2:15 PM   in reply to dmeN

    I just noticed this post. Yes, I tried the above mentioned "UIApplicationExitsOnSuspend" thing. Works great.

     

    Just wanted to clarify that double-clicking the home button doesn't show all the running apps, but rather the most recent apps that have been run.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2013 3:05 PM   in reply to clavin007

    Code written in this way

     

     

    button_exit.addEventListener(MouseEvent.CLICK,Exit1);

    function Exit1(Event:MouseEvent):void

    {

              NativeApplication.nativeApplication.exit();

    }

     

     

    Welcome

     

    Ali Almatrudi

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points