Exit Application When Click Button - iOS

exit application when click button - iOS

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.

iOS: Exit from the app to Home Screen programmatically with gracefully exit with animation?

Code:

   @IBAction func minimizeOrKillApp(){            
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
//Comment if you want to minimise app
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { (timer) in
exit(0)
}
}

Output

Download sample code

It is not recommended and your app will be rejected. We all are the developers and We know to how to approve it from reviewer team

Apple developer question

How to close an application programmatically when the user taps on a button

Please see:
How do I programmatically quit my iPhone application?

WARNING: It is possible to quit the
application by calling exit.
Applications calling exit will appear
to the user to have crashed, rather
than performing a graceful termination
and animating back to the Home screen.
Such usage provides a negative
experience and is strongly
discouraged.

Proper way to exit iPhone application?

Have you tried exit(0)?

Alternatively, [[NSThread mainThread] exit], although I have not tried that it seems like the more appropriate solution.

Clear and exit button

1) How can I clear all entered textfields and label text when pressed clear button ?

For Your Questions 1 Remove all Subview form any views

[self.view.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];

and if you Only looking to clear the text inti UILabel or UITextField

-(IBAction)buttonPressed:(id)sender
{
yourFirstTxtField.text=@"";
yourLabelField.text=@""
}

And

2) How can I exit from application when pressed exit button ?

And for The Second one use the How do I programmatically quit my iOS application?On the iPhone App Development 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 Also Apple provide Human Interface Guidelines show something like this.

Don’t Quit Programmatically

But there is some way to do this like exit(0)

and [[NSThread mainThread] exit], andI have not tried.



Related Topics



Leave a reply



Submit