zoukankan      html  css  js  c++  java
  • ios 监听app从后台恢复到前台

    正常情况下,在AppDelegate中实现下面两个方法,能够监听从后台恢复到前台


    [cpp] 
    - (void)applicationDidEnterBackground:(UIApplication *)application 

        log4info(@"---applicationDidEnterBackground----"); 
       //进入后台  

     
    - (void)applicationDidBecomeActive:(UIApplication *)application 

     
        NSLog(@"---applicationDidBecomeActive----"); 
        //进入前台  
     
         

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        log4info(@"---applicationDidEnterBackground----");
       //进入后台
    }

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {

        NSLog(@"---applicationDidBecomeActive----");
        //进入前台

       
    }


    但是单个UIViewController怎么监听呢

    在-viewDidLoad方法中,添加一下代码监听notification


    [cpp]
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(someMethod:) 
                                                 name:UIApplicationDidBecomeActiveNotification object:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(someMethod:)
                                                 name:UIApplicationDidBecomeActiveNotification object:nil];
    别忘了在-dealloc中将监听移除:


    [cpp] 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 

    [[NSNotificationCenter defaultCenter] removeObserver:self];

  • 相关阅读:
    Android屏幕适配全攻略(最权威的官方适配指导)--转
    Android实现全屏的三种方式
    Mysql锁(翻译)
    mysql5.6主从配置
    jvm加载类(更新中)
    如何定位jdk中的native方法源码?
    光学字符识别OCR-2
    光学字符识别OCR
    关于freetype在安装中的遇到的问题
    锚点链接
  • 原文地址:https://www.cnblogs.com/wanghuaijun/p/5659907.html
Copyright © 2011-2022 走看看