zoukankan      html  css  js  c++  java
  • 测试App运行状态

    示例代码:

    #import "AppDelegate.h"
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        NSLog(@"%@",NSStringFromSelector(_cmd));//_cmd是iOS内置的参数可以直接打印当前的方法名
        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.
        // 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.
        NSLog(@"%@",NSStringFromSelector(_cmd));
    }
    
    - (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.
        NSLog(@"%@",NSStringFromSelector(_cmd));
    }
    
    - (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.
        NSLog(@"%@",NSStringFromSelector(_cmd));
    }
    
    - (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.
        NSLog(@"%@",NSStringFromSelector(_cmd));
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        NSLog(@"%@",NSStringFromSelector(_cmd));
    }
    
    @end

    1.首次运行打印出来的消息是:

    2016-06-30 17:17:19.610 测试状态改变[53450:338456] application:didFinishLaunchingWithOptions:

    2016-06-30 17:17:19.613 测试状态改变[53450:338456] applicationDidBecomeActive:

    2.程序切换到后台时,打印出来的消息是:

    2016-06-30 17:17:24.516 测试状态改变[53450:338456] applicationWillResignActive:

    2016-06-30 17:17:25.096 测试状态改变[53450:338456] applicationDidEnterBackground:

    3.程序从后台切换到前台时,打印出来的消息是:

    2016-06-30 17:19:18.335 测试状态改变[53450:338456] applicationWillEnterForeground:

    2016-06-30 17:19:18.849 测试状态改变[53450:338456] applicationDidBecomeActive:

    4.程序终止时,并不会执行  applicationWillTerminate:这个方法,而是直接报错。

  • 相关阅读:
    Oracle JDBC:驱动版本区别与区分 [转]
    项目管理: Alpha,Beta,RC,GA,Release
    J2EE: JCA (Java Connector Architecture) [转]
    HTML:Event [转]
    JavaScript:inherits
    HTML5 Canvas
    Selenium1 Selenium2 WebDriver
    HTML5 Canvas:初始Canvas
    License友好的前端组件合集
    JavaSe:Comparator
  • 原文地址:https://www.cnblogs.com/wobuyayi/p/5630687.html
Copyright © 2011-2022 走看看