天天看点

iOS开发 --- App强制退出

最近项目中用到强制退出App,做个笔记。

关键代码 

/**
  退出App
  */
-(void)exitApplication {
    AppDelegate *app = (AppDelegate*)[UIApplication sharedApplication].delegate;
    //此处如果不强转 AppDelegate,会报警告:Initializing 'AppDelegate *__strong' with
    // an expression of incompatible type 'id<UIApplicationDelegate>
    UIWindow *window = app.window;
    window.alpha = 0;
    window.frame = CGRectMake(0, window.bounds.size.width, 0, 0);
    exit(0);
}
           

相关文章

iOS强制退出APP