IOS Force Quit Program app code

Source: Internet
Author: User

1, the first PO code

Exit Program 1

12345678910111213141516171819202122232425262728293031 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:self.exitapplication message:@""delegate:selfcancelButtonTitle:self.exityes otherButtonTitles:self.exitno,nil];          [alert show];- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    if(buttonIndex ==0){                        [selfexitApplication ];            }}- (void)exitApplication {        AppDelegate *app = [UIApplication sharedApplication].delegate;    UIWindow *window = app.window;    Animation 1    [UIView animateWithDuration:1.0f animations:^{        window.alpha = 0;        window.frame = CGRectMake(0, window.bounds.size.width, 0, 0);    } completion:^(BOOLfinished) {        exit(0);    }];    //exit(0);    }
Exit Program 2://--------------------------------Exit program 2-----------------------------------------//- (void) exitapplication {[UIView beginanimations:@"exitapplication"Context:nil]; [UIView setanimationduration:0.5];    [UIView setanimationdelegate:self]; //[UIView setanimationtransition:uiviewanimationcurveeaseout ForView:self.view.window Cache:no];[UIView setanimationtransition:uiviewanimationcurveeaseout ForView:self.window Cache:no];    [UIView setanimationdidstopselector: @selector (animationFinished:finished:context:)]; //self.view.window.bounds = CGRectMake (0, 0, 0, 0);Self.window.bounds= CGRectMake (0,0,0,0); [UIView commitanimations];}- (void) animationfinished: (NSString *) Animationid finished: (NSNumber *) finished context: (void*) Context {if([Animationid Compare:@"exitapplication"] ==0) {exit (0); }}

2. Exit (1), Abort (), assert (0) in the program;

Let's take a look at how the program died:

There are roughly three deaths in the program: natural death, i.e., a return 0 in main (), and suicide, when the program finds that it doesn't make any sense to live any longer, it usually chooses to commit suicide. Of course, this suicide is also a request-type suicide, that is, request the OS to kill themselves. There are three ways: void exit (int status) and void abort (void), assert (condition). He kills, unlike the reality that the murders in the program family are often done by their own loved ones, and usually the kinsman is his biological father (or mother?). )。 The language itself does not provide the murder weapon, which is often provided by the OS directly or indirectly (through some process libraries, such as Pthread). Natural death is the most perfect ending, he is the last thing we want to see, although suicide is a necessity, but the initiative is still controlled by the program itself; When abort is invoked, the program exits directly and the destructor for any object does not call


Abort: This is the default program End function, which may or may not be opened with the closed file to refresh
or delete temporary files, which are related to your design.
Exit: Attach the close open file with return status code to the execution environment and call the return function you registered with Atexit

ASSERT (1) is a macro in OC, only useful in debug mode, when the condition is set up, the program does not terminate, and when the condition is not established, the program terminates.

The Assert (condition) function is recommended in the SO,OC program.

3. Select

Q: How to Exit iOS program in code mode

A: There are no APIs available to exit the iOS app normally.

In iOS, the user clicks the home key to close the app. Your app should meet the following criteria: it cannot invoke the method itself, but should take steps to interact with the user, indicating the nature of the problem and the behavior that the application might take, such as turning on WiFi, using location services, etc. for the user to choose to use;

Warning: Do not use the Exit function, calling exit will cause the user to feel that the program crashed, there will be no smooth transitions and animations when the home key is returned, and that using exit may result in loss of data because calling exit does not call-applicationwillterminate : Methods and Uiapplicationdelegate methods;

The abort function and the Assert macro are recommended if you do need to forcibly terminate the program in development or testing.

IOS Force Quit Program app code

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.