Quit application in titanium (iOS) - ios

What is the equivalent for iOS to:
win.close();
var activity = Titanium.Android.currentActivity;
activity.finish();
Thanks!

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

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.

Related

How to know which Apps are in the background

Is there any possibility to know which apps are in the background (Those apps that appear when you double tap home button)?
For 3rd party apps, no. Not in a reliable, App Store safe, future proof way. Think of your app as siloed, unaware of what else is running, and you'll be pretty much in the mindset Apple want (and try to technically enforce).
For other apps developed by you, you can use shared containers to write load/unload data each time one of your apps opens/closes, and work out what's currently running.
This is not possible on iOS with public api. There might be private api calls that do this, even though I don't think you will have access to them while running in the sandbox. This however might be possible on jailbroken devices, but you will not be able to submit to the app store with such api usage, unless you know how to hide that from apple.
Also please note that apps shown in the app switcher are not necessarily running. The app switcher shows every app that has been running in the past which the user didn't force-quit. If the user does not force quit an app, every app that has ever been launched is shown in the app switcher. If iOS decides to terminate an app because of memory needs, the app is still shown in the app switcher. This is one of the reasons why everyone should implement state restoration, as the user does not know whether an app is currently running or not!

Simulate device buttons inside my app?

I have a view containing 4 buttons:
Home
Lock
Volume up
Volume down
all I'm trying to make is that when you press one of these buttons, my app should do some communication with the device to simulate one of these buttons.
Example: If I click the home button exists within my app, is the same as I press home button in device.
This kind of thing is possible? jailbreak is necessary for this?
None of these functions are available to you if you want to get your app accepted into the App Store. For a while some apps accessed private API's in AVSystemController however it seems recently apps using this method are being rejected. (Although some apps still using the method seem to be left in the app store)
If you want to go down the jailbreak route you'll have to dig into private API's and the headers of the various frameworks.
Also just a note, Apple provides some sort of interface like this through their accessibility options.
To do what you are after would go against Apple Review Guidelines so it will get your app rejected under
2.5 - Apps that use non-public APIs will be rejected
You are not allowed to take the functionality of the Home and Lock away from these buttons and put it within your application.
Though I will not say it is impossible to do if your app is for jailbroken devices. Such as to exit your app you can do exit(0); though I still wouldn't recommend it as it makes it look as though your app has crashed when it hasn't.
For the volume control you can do this with the use of MPVolumeView I would recommend having a read of the Apple Documentation and this question iOS: Accessing device hardware audio volume control

ios 8 openUrl itms-services does not exit current app

In iOS 6 or 7, the app exit to the home screen when I call UIApplication openUrl with a url of itms-services://XXXX to install a new version of my app (using enterprise deployment with ipa files).
In iOS 8, this is no longer the case. Now the app continue running just as nothing has happened, but if I go the home screen, I can see my app icon grayed out, with a downloading pie chart about 66% completed and the text "Downloading..." below. If I now wait for a while (less than a minute), the application is installed correctly and I can start my app again.
Has anyone else experienced this behavior? Have anyone seen any documentation regarding this? I can accept behavioral changes as long as it is documented, but I haven't seen any documentation regarding this.
While forcing the app to crash will technically work, a much better solution (allowing the user to retain the state of the application) would be to simply background the app launching the itms-services link by executing the following.
[[UIApplication sharedApplication] performSelector:#selector(suspend)];
We use this in an app used for distributing test builds to our testers and it works very well, and eliminates the confusion of a tester trying to install an app and having the app stay in front. It also allows them to return to our distribution app and have it pick up where they were.
Yes, you also get the same behaviour when clicking a download link in safari now on iOS8.
I'm not sure why they introduced this change but there isn't really a way around it (unless you force your app to crash with something like exit(0);)
Also, the itms-services url scheme is undocumented and is technically a private api. From experience, you're not allowed to submit apps to the App Store that use it.
I have experienced a similar thing. I have a web page for our internal app store and when I tap on the link I do get a prompt asking if I want to install and when I say yes safari just sits there. The app is downloading on the home screen but under IOS 7 safari would be pushed to the background and you could see where your app is being downloaded to and its progress. Now it appears like nothing is happening. I would love to correct this. Perhaps something has changed in the .plist files the itms-services protocol uses. This protocol is not private it is just reserved for enterprise deployments.

Exit iPhone app, from tab bar controller? [duplicate]

This question already has answers here:
Proper way to exit iPhone application?
(24 answers)
Closed 9 years ago.
I have a tab based app, which last tab button is "Exit" how can I quite iPhone App, on click of that last tab bar?
I can't express how strongly I wouldn't recommend this - just DON'T
This will get your app rejected from the App Store in the Apple App Store Review Process.
If you insist on it though you could use exit(0);
If the user wishes to exit your app they have the Home button at the bottom of the device so there is no need to do this at all, it will create confusion and and look as if the app has crashed.
See this, it states.
There is no API provided for gracefully terminating an iOS application.
Warning: Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.
So this means there is no Public API that will allow you to do this gracefully so your app would get rejected under
2.5 - Apps that use non-public APIs will be rejected
From source Apple Review Guidelines
Basic definition of exit()
exit. The exit statement terminates your program with an exit code. Its prototype is void exit(int exitcode);
exit is used by some operating systems and may be used by calling programs. By convention, an exit code of 0 means that the program finised normally, and any other value means that some error or unexpected results happened.
Also another source that says don't use it is here. That is basically all of the Apple Documentation saying under no circumstance should you be exiting the app programmatically.
We can not send app in background or we can not quit app because Quitting your application or sending it to the background programmatically is a violation of the iOS Human Interface Guidelines, because people tend to interpret this as a crash and apple never allows such apps.
You can exit an iOS Application with the following code
exit(0)
However,
From Apple's Human User Guidelines...
Don’t Quit Programmatically
Never quit an iOS application programmatically because people tend to
interpret this as a crash. However, if external circumstances prevent
your application from functioning as intended, you need to tell your
users about the situation and explain what they can do about it.
Depending on how severe the application malfunction is, you have two
choices.
Display an attractive screen that describes the problem and suggests a
correction. A screen provides feedback that reassures users that
there’s nothing wrong with your application. It puts users in control,
letting them decide whether they want to take corrective action and
continue using your application or press the Home button and open a
different application
If only some of your application's features are not working, display
either a screen or an alert when people activate the feature. Display
the alert only when people try to access the feature that isn’t
functioning.
!!! PLEASE DONT DO IT !!!
an iphone app should not be terminated by user! Your app will be rejected!
check UITabBarDelegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if( item == exitItem ) {
exit(0);
}
}

Programmatically suspend/close the app

How can I suspend/close my iPad app programmatically? I wanted to show the terms of use on app start up. If user presses the Accept button the app should continue. If user presses the Decline button the app should be suspended/closed.
PS : The app is built using Titanium Appcelerator framework.
you could try calling exit() but, to be honest, i doubt that the behaviour you want is desirable. i haven't seen any other apps do it - i'm not sure it'd be considered acceptable by Apple.
You never exit from an iPhone or iPad application.
If it does apple takes it as a crash and surely reject your application.
In your case, the best solution will be displaying another screen which display a message like: "You cannot access the application until you accept the terms" or something like that.
You can use exit(0); whenever you want to exit the app. I have implemented this code in my project and it works perfectly fine for me.

Resources