Terminate iOS application [duplicate] - ios

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.

Related

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

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.

How do I programmatically remove an application from an iOS device? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Programmatically delete my own app
Currently I am working on a iphone application and one of the critical requirement of the application is if a user cannot successfully authenticate after 5 attempts, the application is removed from the user’s iPhone.
How can I achieve this goal?
Being able to alter things outside of the application's own sandbox is a huge security risk that Apple (understandably) has not allowed. Therefore you will not be able to do this. The best you can do is store the result in a persistent value and not allow to app to continue after launching. For bonus points, you can store this value in the iOS keychain so that it will persist between installs if you like, then the user will be forced to reset their ios device to factory defaults to be able to use it again.
Can't be done. The best you can do is to make your app stop functioning after five failed authentication attempts.
you cant. the only one who can have this privilige is the user. You could just make the app to not open anymore, making the user angry and then deleting it afterwards.
Its not possible. You should handle it programmatically like locking the application. Once user is failed for 5 attempts, change your startup viewcontroller and do not allow the user to navigate any where else. Here you can display some message to delete the app.
An application, installed in a non-jailbroken device, is a sandboxed eco-system.
If your app is for App Store, this thing cannot be done. If this app is for a JB device (for In-House apps would be possible, but I think you need root permissions to delete apps), try to remove the app file from disk after the app has gone on background (but I'm quite sure files are locked, so you'll not be able to do it). If this approach, as I guess, doesn't work due to locked files, you can try to search for private APIs.
It's not possible. You only solution is lock the app if authentication not success.

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