IOS forcibly exits the APP code, and ios enforces the app code.

Source: Internet
Author: User

IOS forcibly exits the APP code, and ios enforces the app code.

1. po code first

// Exit program 1

12345678910111213141516171819202122232425262728293031 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:self.exitapplication message:@"" delegate:self cancelButtonTitle:self.exityes otherButtonTitles:self.exitno,nil];           [alert show];- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {    if(buttonIndex ==0){                          [self exitApplication ];             } } - (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:^(BOOL finished) {        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 (), and assert (0) in the program );

 

Let's take a look at the method of program death:

There are roughly three types of program deaths: natural deaths, that is, endless deaths, usually a return 0 in main (); suicide. When the program finds itself no longer active, it usually chooses to commit suicide. Of course, this kind of suicide is also a kind of request-based suicide, that is, request the OS to kill itself. There are three methods: void exit (int status), void abort (void), and assert (condition ). Unlike reality, the killing behavior in the program family is often done by the person himself or herself. Generally, this person is his father (or mother ?). The language itself does not provide weapons for killing. These weapons are often provided directly or indirectly by the OS (through some process libraries, such as pthread. Natural Death is the perfect ending, and he or she is the last thing we don't want to see. Although suicide is a last resort, the initiative is controlled by the program itself. When abort is called, the program will exit directly, and no object destructor will be called.

 

Introduction:

Abort: This is the default program end function. This method may or may not refresh or close open files.
Or delete temporary files, which is related to your design.
Exit: attaches the closed open file and return status code to the execution environment, and calls the return function you registered with atexit.

Assert (1) is a macro in oc and is only useful in debug mode. When the condition is set, the program will not be terminated. When the condition is set, the program will be terminated.

We recommend that you use the assert (condition) function in the so and oc programs.

 

3. Select

Q: How can I exit the iOS program using code?

 

A: No API is provided for exiting the IOS app normally.

 

In IOS, the user clicks the Home Key to close the application. Your application should meet the following conditions: it cannot call the method by itself, but should take measures to interact with the user, indicating the nature of the problem and the behavior that the application may take, such as enabling WIFI, use the positioning service for user selection;

 

Warning do not use the exit function. Calling exit will make the user feel that the program has crashed and there will be no smooth transition and animation effects returned by pressing the Home key. In addition, using exit may cause data loss, because calling exit does not call-applicationWillTerminate: method and UIApplicationDelegate method;

 

If the program needs to be forcibly terminated during development or testing, we recommend that you use the abort function and assert macro;

 

Related Article

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.