IOS初学-生命周期

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21153627/article/details/83828129

这里主要是记录ios的生命周期

运行项目之后可以进行  打开   退出到后台。唤醒  锁屏  后台清除等操作,观察在xcode中打出的log来理解每个方法的调用时机

funcapplication(_application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool{

        // Override point for customization after application launch.

        print(">>>>>>>>>>>>>>程序加载完成");

        returntrue

    }



    funcapplicationWillResignActive(_application: UIApplication) {

        // 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 invalidate graphics rendering callbacks. Games should use this method to pause the game.

        print(">>>>>>>>>>>>>>程序进入非活动状态。不在接收消息和事件");

    }



    funcapplicationDidEnterBackground(_application: UIApplication) {

        // 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.

        print(">>>>>>>>>>>>>>程序进入后台,进入后台仍要进行操作在此处添加");

    }



    funcapplicationWillEnterForeground(_application: UIApplication) {

        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

        print(">>>>>>>>>>>>>>程序在后台时,将要回到前台时调用此方法");

    }



    funcapplicationDidBecomeActive(_application: UIApplication) {

        // 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.

        print(">>>>>>>>>>>>>程序进入活动状态将执行此方法");

    }



    funcapplicationWillTerminate(_application: UIApplication) {

        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

        print(">>>>>>>>>>>>>程序将要推出执行此方法对数据和文件清除在此处调用");

    }

猜你喜欢

转载自blog.csdn.net/qq_21153627/article/details/83828129