4

What is the equivalent for iOS to:

 win.close();
 var activity = Titanium.Android.currentActivity;
 activity.finish();

Thanks!

Sebastián
  • 232
  • 2
  • 11

2 Answers2

6

There isn't (in Titanium). Further, Apple explicitly discourages this:

"An iOS app never displays a Close or Quit option" - Apple, HIG p27 https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/MobileHIG.pdf

There are existing SO answers regarding this:

On the iPhone there is no concept of quitting an app. The only action that should cause an app to quit is touching the Home button on the phone, and that's not something developers have access to.

According to Apple, your app should not terminate on its own. Since the user did not hit the Home button, any return to the Home screen gives the user the impression that your app crashed. This is confusing, non-standard behavior and should be avoided.

See existing SO answer here: Proper way to exit iPhone application?

If, after all this, you want a non-standard, will-probably-get-your-app-rejected solution (or if your app isn't destined for the app store, and will be distributed privately through enterprise distribution or personal use), you can create a module that calls [[NSThread mainThread] exit].

Community
  • 1
  • 1
Dawson Toth
  • 5,580
  • 2
  • 22
  • 37
  • This is not true. Many apps include an exit option, including ours, under certain conditions. `exit(0)`. But this does not answer the answer, as it asks for code in Titanium. – Léo Natan Mar 24 '14 at 18:11
  • 1
    "An iOS app never displays a Close or Quit option" https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/MobileHIG.pdf – Dawson Toth Mar 24 '14 at 20:36
  • 2
    Did you notice that I did answer the question? Read it again, Leo Natan. "There isn't" -- Titanium does NOT expose this functionality. Then read my last paragraph, including the code, and links to the documentation for creating modules. What precisely is not true? If you provide more constructive feedback, please do so and I will update my answer. – Dawson Toth Mar 24 '14 at 20:40
  • 2
    I agree 100% with Dawson on this. Further, I would even go as far to say that if your app "needs" to be able to quit then you've designed it wrong. – Fogmeister Mar 25 '14 at 18:16
  • @Fogmeister Or you are too narrow-minded to think of all app states and all app requirements of both consumer-oriented and more importantly, enterprise-oriented security applications. – Léo Natan Mar 25 '14 at 19:45
  • Lol! Yeah... so please let me know why you would need to **quit** an app. (Even when apple basically says don't do it). I'd love to hear what great wisdom you have picked up on that Apple has missed. – Fogmeister Mar 25 '14 at 19:54
  • Enterprise is a good example of something I didn't consider. I tend to avoid asking for the logic behind the decisions there. :) Updated the last paragraph of the answer to reflect this as a possibility. – Dawson Toth Mar 25 '14 at 20:05
  • Gonna make me down vote again (retracted the previous down vote). While not "recommended", it will not get the app rejected. No. – Léo Natan Mar 25 '14 at 20:53
  • @LeoNatan I'd love to here your ground breaking ideas on why a "Quit App" button is required. You're letting me down though, you haven't come up with anything yet. :( – Fogmeister Mar 26 '14 at 10:31
1

There is no way to close iOS application using just Titanium SDK. If you really need that you have to create your own small Titanium Module with just one method:

-(id)example:(id)args
{
    // example method
    exit(0);
    return @"Application Exit";
}

However, remember that calling exit() is strongly not recommended for iOS applications and can lead to rejection from App Store.

daniula
  • 6,898
  • 4
  • 32
  • 49