ios app响应background,foreground 事件实现

1 经过AppDelegate 实现ios

App进入后台事件方法app

- (void)applicationDidEnterBackground:(UIApplication *)applicationspa

APP进入前台的事件方法server

- (void)applicationWillEnterForeground:(UIApplication *)application事件

 

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

举例string

- (void) viewWillAppear:(BOOL)animated{  io

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

}  class

- (void) appWillEnterForegroundNotification{  

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

}  

-(void) viewDidDisappear:(BOOL)animated{  

    [[NSNotificationCenter defaultCenter] removeObserver:self];      

}  

注意:在UIViewController类中viewDidUnload方法在ios6之后过时失效

相关文章
相关标签/搜索