当应用程序再次激活时,我需要触发一个方法。我找到了这个useful https://stackoverflow.com/questions/5277940/why-does-viewwillappear-not-get-called-when-an-app-comes-back-from-the-backgroun关于该主题的问题,但不幸的是这对我来说还不够,我无法决定在我的情况下应该使用哪一个..
我有这个方法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:
已首先被调用,但我不确定顺序是否始终相同。