UIApplicationDidBecomeActive与UIApplicationWillEnterForeground的区别

当应用程序再次变为活动状态时,我需要触发一个方法。 我发现这个主题的这个有用的问题,但不幸的是,这对我来说还不够,我无法决定在我的情况下应该使用哪一个……

我在viewDidAppear:有这个方法,每当应用程序再次变为活动状态时,我想再次调用它。

 - (void)viewDidLoad { [PubNub requestFullHistoryForChannel:x-channel withCompletionBlock:^(NSArray *msg, PNChannel *channel, PNDate *fromDate, PNDate *toDate, PNError *error) { AppDelegate *delegateArray = (AppDelegate*)[[UIApplication sharedApplication] delegate]; delegateArray.mainArray = [NSMutableArray arrayWithArray:msg]; [self setupContent]; }]; } 

基于另一个问题,我将这些通知放入viewDidLoad

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

这里是应用程序再次变为活动状态时调用的方法。

 - (void)applicationIsActive:(NSNotification *)notification { NSLog(@"Application Did Become Active"); } - (void)applicationEnteredForeground:(NSNotification *)notification { NSLog(@"Application Entered Foreground"); } 

那么有人可以告诉我,我应该在哪个地方放置requestFullHistoryForChannel:方法,为什么? 正如我在控制台中看到的那样, applicationEnteredForeground:已经被调用,但我不确定序列是否始终相同。

applicationDidBecomeActive: – 让您的应用知道它即将成为前台应用。 使用此方法进行最后一分钟准备。(在appdelegate文件中)

在此方法中调用您的方法,以便在您的应用程序重新启动时调用它