2

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.

Community
  • 1
  • 1
rihekopo
  • 3,241
  • 4
  • 34
  • 63
  • 1
    Try opening the control center, notification center, siri, the multi-task UI, etc, while your app is open and see which notifications are sent. – i_am_jorf Oct 31 '14 at 17:34

1 Answers1

0

applicationDidBecomeActive:—Lets your app know that it is about to become the foreground app. Use this method for any last minute preparation.(inside appdelegate file)

call your method inside this method so it will get called when your application get restarted

Rudra
  • 241
  • 1
  • 3
  • 9