iOS应用程序的生命周期

iOS应用程序的生命周期

//——————————————————————————整个应用的入口函数
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    return YES;
}

//——————————————————————————从不活跃状态到活跃状态
- (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.

    //应用程序从活跃状态切换到不活跃状态这个函数将会被调用(消息),这也会在某些临时状态发生,(比如来了电话。SMS短信这个函数也会被调用)或者当用户退出了应用程序,他开始切换到后台模式
    // 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.
    //我们应该做什么???用这个方法我们要暂停正常的任务,关闭定时器,降低opengless的游戏频率,暂停游戏
}

//——————————————————————————已经进入到后台

- (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
{
    // 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
{
    // 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.
   //重新启动被暂停的业务,如果如果应用程序在后台,那么这里要刷新UI(User Interface)
}

//

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

   //当应用程序停止回调函数,这个只有在<ios4.0调用  活着大于 iOS>4.0
   //设置了 不能后台模式调用
}



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。