• ios app响应background,foreground 事件实现


    1 通过AppDelegate 实现

    App进入后台事件方法

    - (void)applicationDidEnterBackground:(UIApplication *)application

    APP进入前台的事件方法

    - (void)applicationWillEnterForeground:(UIApplication *)application

    2UIViewController类中通过对Background ,Foreground事件的通知的侦听,进行实现

    举例

    - (void) viewWillAppear:(BOOL)animated{  

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForegroundNotification) name:UIApplicationWillEnterForegroundNotification object:nil];  

    }  

    - (void) appWillEnterForegroundNotification{  

        NSLog(@"trigger event when will enter foreground.");  

    }  

    -(void) viewDidDisappear:(BOOL)animated{  

        [[NSNotificationCenter defaultCenter] removeObserver:self];      

    }  

    注意:在UIViewController类中viewDidUnload方法在ios6以后过期失效

  • 相关阅读:
    Python-异常处理机制
    递归函数——斐波那契数列j
    函数及相关操作
    字符串及相关操作
    集合及相关操作
    元组
    字典
    列表元素增删改排操作
    multiprocessing模块简单应用
    02 for循环创建进程
  • 原文地址:https://www.cnblogs.com/macroxu-1982/p/4457530.html
Copyright © 2020-2023  润新知