I have a simple app which loads text from a RSS when there is no internet it displays a empty tableView. I would like to make it so that when there is no internet it gives some text saying there is no internet available and a button to try to reconnect.
In the attempt to make this I used Tony Million's Reachability class as in this question. I set a boolean to YES and NO in the functions like this :
- (void)testInternetConnection
{
internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
// Internet is reachable
internetReachableFoo.reachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^
{
NSLog(@"Yayyy, we have the interwebs!");
internetConnect = YES;
});
};
// Internet is not reachable
internetReachableFoo.unreachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^
{
NSLog(@"Someone broke the internet :(");
internetConnect = NO;
});
};
[internetReachableFoo startNotifier];
}
Now when I try to check the boolean in the viewDidLoad function it will always return before the function is finished. This is because the Reachability class is in a background thread. I don't know how I can let my code wait for the result before proceeding.
So I should let my code wait for result and then depending on the result make the tableView disappear and change it to text with a button.
I want to know :
- How to make my code wait for result of the background thread.
- How to reconnect. (with a loading bar or something to let the user know it is searching for connection).