AI智能
改变未来

iOS程序的执行顺序

1 进入程序的入口

进入main函数,设置Appdelegate成为在主函数的代理

2 程序完成加载

-[appDelegate application:didFinishLaunchingWithOptions:]

3 创建window窗口

4程序被激活

-[APPDelegate applicationDidBecomeActive:]

5点击Home键程序取消激活状态

程序取消激活状态

– [AppDelegate applicationWillResignActive:]

程序进入后台

-[APPDelegate applicationDidEnterBackground]

6点击进去工程

程序进去前台

-[APPDelegate applicationWillEnterForeground:]

程序被激活

-[APPDelegate applicationDidbecomeActive:]

下面是每个方法的作用

- (void)applicationWillResignActive:(UIApplication *)application{NSLog(@\"程序取消激活状态\");NSLog(@\"%s\", __FUNCTION__);// Sent when the application is about to move from active to inactive state. This can occur for certain types oftemporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application andit begins the transition to the background state.当应用程序发送即将从活跃不活跃的状态。这可能发生某些类型的暂时中断(如传入的电话或短信)或当用户退出应用程序,它开始过渡到后台状态// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games shoulduse this method to pause the game.使用这种方法暂停正在进行的任务,禁用计时器,和节流OpenGL ES帧率。游戏应该使用这种方法暂停游戏}- (void)applicationDidEnterBackground:(UIApplication *)application{NSLog(@\"程序进入后台\");NSLog(@\"%s\", __FUNCTION__);// Use this method to release shared resources, save user data, invalidate timers, and store enough applicationstate 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.如果您的应用程序支持后台执行,而不是调用此方法applicationWillTerminate:当用户退出。}- (void)applicationWillEnterForeground:(UIApplication *)application{NSLog(@\"程序进入前台\");NSLog(@\"%s\", __FUNCTION__);// Called as part of the transition from the background to the inactive state; here you can undo many of thechanges made on entering the background.称为部分从背景过渡到非活动状态,在这里你可以撤消的许多进入背景所做的更改。}- (void)applicationDidBecomeActive:(UIApplication *)application{NSLog(@\"程序被激活\");NSLog(@\"%s\", __FUNCTION__);// Restart any tasks that were paused (or not yet started) while the application was inactive. If the applicationwas previously in the background, optionally refresh the user interface.重启任何任务暂停(或没有开始),而应用程序是不活跃的。如果应用程序在后台以前,可选更新用户界面。}- (void)applicationWillTerminate:(UIApplication *)application{NSLog(@\"程序被终止\");NSLog(@\"%s\", __FUNCTION__);// Called when the application is about to terminate. Save data if appropriate.See also applicationDidEnterBackground:.当应用程序即将终止。如果适当的保存数据。参见applicationDidEnterBackground:}

  • 点赞
  • 收藏
  • 分享
  • 文章举报

淡定丶东发布了3 篇原创文章 · 获赞 0 · 访问量 604私信关注

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » iOS程序的执行顺序