Search code examples
iosuitabbarcontrollernsurlconnectionviewwillappear

Change Tab view after certain time interval received as response from Server request


In an application having UITabBarController, I want to implement following scenario:

When user is on 'X' Tab, he/she does something & then move to another tabs. And again he/she comes back to 'X' tab(say after 5minutes-> this is important as I may change 5min to 10min in future), then I want to show some message like your 'Session is expired'.

Whenever user comes back 'X' Tab, it need to make server request to get response code. Depending upon that I want to show the pop-up 'Session is expired'.

I thought following way to implement:

In every viewWillAppear: method of all views being loaded inside 'X' Tab viewController of UITabBarController I will make server request & check for response & perform operations accordingly.

But it will involve many server request which I want to avoid.

I am not able to conclude with solution. How can I achieve my requirement.?

Thanks a lot in advacnce.


Solution

  • You need to perform this only once in tab bar delegate method -

    - (void)tabBarController:(UITabBarController *)tabBarController 
        didSelectViewController:(UIViewController *)viewController
    

    Inside this method based upon the tab index you can have your code, you won't need to write the code in several view controllers.