host on Github
在AppDelegate.m中的- (void)applicationWillEnterForeground:(UIApplication *)application;方法在APP即将转到foreground时会被调用。
具体的UIViewController中,可以在
-(void)viewWillAppear:(BOOL)animated;
方法里添加对这一事件的监听:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillEnterForegroundNotification)
name:UIApplicationWillEnterForegroundNotification
object:nil];
appWillEnterForegroundNotification即要调用的方法。
最后在UIViewController的-(void)viewWillDisappear:(BOOL)animated中要移除这个observer
[[NSNotificationCenter defaultCenter] removeObserver:self];
comments powered by Disqus