AppDelegate 中的函數介紹

  • – (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions;
    當應用程序加載時觸發, 在方法中創建 window 窗口對象, 讓 window 對象成爲應用程序主窗口並且可視
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];//讓 window 對象成爲應用程序主窗口並且可視.
    return YES;
}
  • – (void)applicationWillResignActive:(UIApplication *)application;
    當應用程序將要取消活躍狀態時觸發, 可以使用該方法暫停掉正在執行的任務, 讓定時器無效, 暫停遊戲等.
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
  • – (void)applicationDidEnterBackground:(UIApplication *)application;
    當應用程序進入後臺時觸發. 釋放共享資源, 保存用戶數據, 讓 timer 無效, 當應用程序退出時, 該方法會被 applicationWillTerminate: 方法替代
- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
  • – (void)applicationWillEnterForeground:(UIApplication *)application;
    當應用程序將要進入前臺時觸發. 繼續進入後臺時被暫停的任務.
- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
  • – (void)applicationDidBecomeActive:(UIApplication *)application;
    當應用程序成爲活躍狀態時觸發. 重新啓動, 當應用程序進入不活躍狀態(休眠)時暫停的任務. 如果之前應用程序在後臺, 此時可以在該方法中進行刷新界面的操作.
- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
  • – (void)applicationWillTerminate:(UIApplication *)application;
    當應用程序結束時觸發(把 applicationDidEnterBackground替換掉)
- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章