• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Apr 17, 2012 Apr 17, 2012

Copy link to clipboard

Copied

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!

TOPICS
ActionScript

Views

11.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 18, 2012 Apr 18, 2012

Copy link to clipboard

Copied

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><key>UIApplicationExitsOnSuspend</key><true/>]]>

    </InfoAdditions>

    <requestedDisplayResolution>standard</requestedDisplayResolution>

  </iPhone>

Specifically, you just want to add:

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

To the CDATA...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2012 Apr 18, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 19, 2012 Apr 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 10, 2013 Jan 10, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2012 Apr 19, 2012

Copy link to clipboard

Copied

Hi,

If I want to have the user click on the home button or any button that I have created and then close the game, how do I attempt to do that within Actionscript?

Within the event handler for the click button, surely I won't be typing the entire iPhone tag XML and add in <key>UIApplicationExitsOnSuspend</key><true/> right?   I have also read in a lot of articles that you have to change within the XML file, but how do you control that within Actionscript?

Thanks for answering!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 19, 2012 Apr 19, 2012

Copy link to clipboard

Copied

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.

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2012 Apr 19, 2012

Copy link to clipboard

Copied

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/NativeApplication.h...

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

LATEST

Code written in this way

button_exit.addEventListener(MouseEvent.CLICK,Exit1);

function Exit1(Event:MouseEvent):void

{

          NativeApplication.nativeApplication.exit();

}

Welcome

Ali Almatrudi

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines