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!
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...
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.
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.
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.
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!
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.
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Code written in this way
button_exit.addEventListener(MouseEvent.CLICK,Exit1);
function Exit1(Event:MouseEvent):void
{
NativeApplication.nativeApplication.exit();
}
Welcome
Ali Almatrudi