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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章