首页 > 移动平台 > 详细

ios app响应background,foreground 事件实现

时间:2015-04-26 12:09:36      阅读:292      评论:0      收藏:0      [点我收藏+]

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以后过期失效

 

ios app响应background,foreground 事件实现

原文:http://www.cnblogs.com/macroxu-1982/p/4457530.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!