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:这个方法,而是直接报错。

  • 相关阅读:
    HDU——1215七夕节(因数和)
    UVa——400Unix ls(字典序文本处理输出iomanip)
    廖雪峰Java5集合-3Map-Properties的使用
    python图片和字符串的转换
    廖雪峰Java5集合-3Map-1使用Map
    廖雪峰Java5集合-2List-2编写equals方法
    廖雪峰Java5集合-1Java集合简介-1Java结合简介
    廖雪峰Java4反射与泛型-3泛型-7泛型和反射
    廖雪峰Java4反射与泛型-3范型-6super通配符
    廖雪峰Java4反射与泛型-3范型-5extends通配符
  • 原文地址:https://www.cnblogs.com/wobuyayi/p/5630687.html
Copyright © 2011-2022 走看看