user1001011
user1001011

Reputation: 41

iPhone viewwillappear on application entering foreground

I have an application where there are 3 tabs to calculate distance and all. When I first launch the app, on clicking 3 rd tab some network call is happening. Now I put the application to background. When the application comes to foreground, it should call viewwillappear to go for the network call again. but it is not happening. it is not calling viewwillappear.

How can I check when application comes to foreground, it should check for 3rd tab and call network method

Please help me

Upvotes: 0

Views: 864

Answers (4)

Rajneesh071
Rajneesh071

Reputation: 31091

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    NSLog(@"%d",tabBar.selectedIndex);
    if (tabBar.selectedIndex == 2) {
        NSLog(@"Your work");
    }
}

Upvotes: 0

Jean-Luc Godard
Jean-Luc Godard

Reputation: 1883

- (void)applicationDidEnterBackground:(UIApplication *)application {
           if(tab3){
          [viewController3 netWorkCallFromHere];
    } 

}

in this approach you will have to declare BOOL tab3 in Appdelegate.

set it true in third viewController and set it false in another viewController .

when it returns from the background then it will check the flag and it will work accordingly.

Upvotes: 0

Abdullah Umer
Abdullah Umer

Reputation: 4634

When application comes to foreground,

- (void)applicationWillEnterForeground:(UIApplication *)application;

of the app delegate is called.

You can restart all your paused tasks in:

- (void)applicationDidBecomeActive:(UIApplication *)application;

Upvotes: 1

John Smith
John Smith

Reputation: 2032

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    //save in NSUserDefaults (or wherever) which tab is currently active
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // read from NSUserDefaults which tab was active before, 
    // and use an IF statement to control the further behavior
}

Upvotes: 0

Related Questions