[iOS]主动退出APP方法
官方SDK方法(突然消失,但在长按APP列表中依旧出现快照):
exit(0); // 退出APP
带动画效果的退出:
- (void)exitApplication { [UIView beginAnimations:@"exitApplication" context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationTransition:UIViewAnimationCurveEaseOut forView:self.window cache:NO]; [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; 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); } }
AppDelegate *app = [UIApplication sharedApplication].delegate; UIWindow *window = app.window; [UIView animateWithDuration:0.4f animations:^{ window.alpha = 0; CGFloat y = window.bounds.size.height; CGFloat x = window.bounds.size.width / 2; window.frame = CGRectMake(x, y, 0, 0); } completion:^(BOOL finished) { exit(0); }];
Private API:
[[UIApplication sharedApplication] terminateWithSuccess]; \\ 或者 [[UIApplication sharedApplication] performSelector:@selector(terminateWithSuccess)];
这个代码显示效果很喜欢啊
用了Crayon Syntax Highlighter插件,支持的语言挺多的,其实用markdown更方便。