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

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);
}
}

Related

Terminate iOS application [duplicate]

This question already has answers here:
Proper way to exit iPhone application?
(24 answers)
Closed 3 years ago.
I'm allowing language change feature inside my application. As user select new language feature inside the application I need to quit the application and user will have to start it again. For quitting I'll show an alert to user that you have to restart the application for language change to complete.
Now how can I use manual termination of iOS app and make it approve from Apple.
PS: Facebook do the same for language change. They tell the user that app needs to restart for language change to take place. Some other apps also kills the application on some alert tap.
exit(0)
you can solve your problem by this, but this is forbidden by Apple. You should set your app to your Home page when you change your language.
let viewController = HomeViewController()
UIApplication.shared.keyWindow.rootViewController = viewController
Ankur gave you the correct answer: You can use exit to terminate your app but Apple does not allow apps to terminate themselves. Your app will be rejected from the app store if you do that.
Instead, you should refactor your app so you have the ability to tear down your entire UI and rebuild it. Delete all your view controllers and replace the root view controller as Ankur says.

Companion app terminated when enabling full access for keyboard

I'm developing a custom keyboard extension for iOS and part of the companion (main) application is an on-boarding tutorial guiding the user through how to install the keyboard.
The final step in this tutorial is to enable full access in the device's settings, but doing so terminates my application:
Message from debugger: Terminated due to signal 9
Once the user returns to my application after enabling full access, he is supposed to continue the tutorial from where he left off. However, since the application was terminated, he must now start from the beginning again.
I could solve this with some clever (read hacky) hardcoded logic, however I would much rather the application not terminate when enabling full access.
My question is as follows: Is this intended functionality or a bug? Is there something I could do to prevent this from happening?
Edit 1:
I just wanted to point out that despite the signal 9, I do not believe this to be a memory issue with my app - the memory usage is extremely low, especially when the app is in the background. The application terminates exactly the same moment I press Allow on the "Allow Full Access for..." popup.

Quit application in titanium (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.

exit application when click button - iOS [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Exit application in iOS 4.0
I have a AlertView which displays some text and an "OK" button. Is there any way to exit application when clicked on OK button?
exit(X), where X is a number (according to the doc) should work.
But it is not recommended by Apple and won't be accepted by the AppStore.
Why? Because of these guidelines (one of my app got rejected):
We found that your app includes a UI control for quitting the app.
This is not in compliance with the iOS Human Interface Guidelines, as
required by the App Store Review Guidelines.
Please refer to the attached screenshot/s for reference.
The iOS Human Interface Guidelines specify,
"Always Be Prepared to Stop iOS applications stop when people press
the Home button to open a different application or use a device
feature, such as the phone. In particular, people don’t tap an
application close button or select Quit from a menu. To provide a good
stopping experience, an iOS application should:
Save user data as soon as possible and as often as reasonable because
an exit or terminate notification can arrive at any time.
Save the current state when stopping, at the finest level of detail
possible so that people don’t lose their context when they start the
application again. For example, if your app displays scrolling data,
save the current scroll position."
> It would be appropriate to remove any mechanisms for quitting your
app.
Plus, if you try to hide that function, it would be understood by the user as a crash.
You can use exit method to quit an ios app :
exit(0);
You should say same alert message and ask him to quit
Another way is by using [[NSThread mainThread] exit]
However you should not do this way
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.

iOS - kill the app with a button?

I have an app that runs for a while, but needs to be reset every day, because it's lifecycle is a bit different than most other apps. It seems that the easiest way to do this is to kill the app and re-launch it.
I found a solution that kills the app when the home button is tapped:
In your application's Info.plist, add a boolean key
UIApplicationExitsOnSuspend with the value YES
This is not something that I want to do. I need to give the user an option to kill/reset the app before it is used. I can certainly ask the user to double tap the home key and kill the app with a long press>x. Yet this is too complex for some users.
Another simple solution would be to have a button do something crashworthy, like divide by 0, although I'm not sure if the app store would penalize my app for "crashing" every single day for all users.
Has anyone found a way to add an "exit" button to an iPhone app? In android, I could do system.exit(0), which worked. What's the iPhone alternative?
iOS Human Interface Guide says -
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. ...
exit(0); can terminate the application (0 is a normal code), but Apple don't like this approach, and the application would be rejected in review.

Resources