chinthakad
chinthakad

Reputation: 979

kNetworkReachabilityChangedNotification of Reachability API

In my project I'm using Reachability API. I followed the code example which have given with
Reachability API Documentation.

In my App Delegate I have implemented applicationDidFinishLaunching method as follow,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the
    // method "reachabilityChanged" will be called. 
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];

    hostReach = [[Reachability reachabilityWithHostName: NSLocalizedString(@"SERVICE_HOST_URL", nil)] retain];
    [hostReach startNotifier];
    [self updateReachabilityStatus:hostReach];

    self.rootViewController = [[SearchRootViewController alloc] initWithNibName:@"SearchRootView" bundle:nil]; 
    self.detailViewController = [[SearchDetailViewController alloc] initWithNibName:@"SearchView" bundle:nil];

    UINavigationController *rootViewNavigationController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
    UINavigationController *detailViewnavigationController = [[UINavigationController alloc] initWithRootViewController:self.detailViewController];

    self.splitViewController = [[UISplitViewController alloc] init];
    self.splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewNavigationController, detailViewnavigationController, nil];

    [rootViewNavigationController release];
    [detailViewnavigationController release];

    self.splitViewController.delegate = self.detailViewController;

    [self.detailViewController setLeftViewController:self.rootViewController];

    [self.window addSubview:[self.splitViewController view]]; 
    [self.window makeKeyAndVisible];
    return YES;
}

When is this kNetworkReachabilityChangedNotification posted?? I noticed that it is not posted till my detailViewController's view is appeared.

But I want to get to know the network status before the view appear. So, need your help to get to know whether it is possible?? If yes, then how ??

thanx

Upvotes: 0

Views: 1152

Answers (1)

lxt
lxt

Reputation: 31294

It can take some time to determine what network connectivity is available: you are asking Reachability to start generating notifications, but then immediately displaying your view controller...and you're also only creating your view controller after starting the reachability notifications, so it's entirely possible a notification is sent before your view controller is instantiated.

A better approach would be to have a holding view that you can use whilst trying to establish the state of the network.

Upvotes: 2

Related Questions