I need to fire a method when the application become active again. I've found this useful question about the topic, but unfortunately it's not enough for me, I can't decide which one should I use in my case..
I have this method in the viewDidAppear:
, and I would like to call it again everytime when the app become active again.
- (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];
}];
}
Based on the other question I placed these notifications into the viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationIsActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationEnteredForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
And here is the methods that being called when the app become active again.
- (void)applicationIsActive:(NSNotification *)notification {
NSLog(@"Application Did Become Active");
}
- (void)applicationEnteredForeground:(NSNotification *)notification {
NSLog(@"Application Entered Foreground");
}
So could somebody tell me that in which one should I place the requestFullHistoryForChannel:
method and why? As I've seen it in the console, the applicationEnteredForeground:
has been called first, but I'm not sure that the sequence is always the same.