Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4566182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:45:10+00:00 2026-05-21T18:45:10+00:00

On Facebook’s iPhone app, the news feed refreshes every time the app becomes active.

  • 0

On Facebook’s iPhone app, the news feed refreshes every time the app becomes active. I would like to do something similar, but I’m concerned about a race condition. The general bootstrapping of my app is as follows:

UIApplicationDelegate

- (void)applicationDidFinishLaunching:(UIApplication*)application
{
  [window addSubview:[self.navigationController view];
  [window makeKeyAndVisible];
}

- (void)applicationDidBecomeActive:(UIApplication*)application
{
  [rootViewController refresh];
}

RootViewController

#pragma mark custom

- (void)refresh
{
  if (self.newsFeedModel == nil) {
   self.newsFeedModel = [[NewsFeedModel alloc] initWithDelegate:self];
  }
  [self.newsFeedModel request];
}

#pragma mark UIViewController

- (void)viewDidLoad
{
  // initialize the table
  // add subviews and whatnot
}

#pragma mark NewsFeedDelegate

- (void)newsFeedSucceeded:(NSMutableArray*)feed
{
  // reload table view with new feed data
}

After sprinkling NSLog everywhere, I determined the order of operations to be:

  1. applicationDidFinishLaunching
  2. applicationDidBecomeActive
  3. refresh
  4. viewDidLoad
  5. newsFeedSucceeded

Notice how refresh is called before the root view has been loaded. While we’re busy querying the server, the root view loads. When the server responds, the root view is populated with the feed. This works in most cases because the network operation takes a long time. However, if the network operation finishes faster than view can be loaded, then I will be attempting to construct the news feed before the view has been loaded. This would be bad. What is the best Cocoa Touch practice for solving this race condition? I would just set a bunch of flags to determine what state we’re in and refresh the news feed depending on the state, but I’m wondering if there were built in events in Cocoa Touch to handle this for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T18:45:11+00:00Added an answer on May 21, 2026 at 6:45 pm

    I think you want to take a look at applicationWillEnterForeground: instead.

    applicationDidBecomeActive: can be called while your app is still running in the foreground. For instance if a text message comes while your app is in the foreground and the user dismisses it, applicationDidBecomeActive: will get called.

    You can subscribe to the UIApplicationWillEnterForegroundNotification event in your RootViewController using NSNotificationCenter. I would do this in RootViewController initWithNibName: or whichever init method you are using.

    Now you just need to call refresh in 2 places. Once at the end of viewDidLoad and again whenever applicationWillEnterForeground: is called.

    This should solve your race condition problem. Since RootViewController is handling it’s own refreshing when it knows it is ok to do so.

    RootViewController

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if(self) {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        // initialize the table
        // add subviews and whatnot
        [self refresh];
    }
    
    
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        [self refresh];
    }
    
    - (void)dealloc
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
        [super dealloc];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Facebook has a nice scroll effect which I would like to replicate with jQuery.
Facebook allows a distance parameter for their search like https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000 They don't say what
Facebook recently introduced the Built-in Like as a built-in Open Graph action (see blogpost
Facebook has done great work on preventing eavesdropping (with tools like Firesheep) by supporting
Facebook recently notified they are deprecating support for app profile pages . Apps created
Facebook gurus, I have been implementing the Facebook Like button for a number of
Facebook Connect seems like the cool new way to leverage a user's Facebook account
[Facebook requestWithGraphPath:@1000029327084_2428832476/likes andParams:params andHttpMethod:@POST andDelegate:nil]; This is what I do for posting my like
Facebook, and twitter rewrite urls and replace characters(like ? or /) with code. Original
Facebook cannot grasp my og:image files and I have tried every usual solution. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.