-1

Here is my code.. hopefully you guys can help me!

When I run the app with internet and close internet later it works perfect, but whenever I start it without internet it won't show the image..

[super viewDidLoad];

[webView loadRequest: [NSURLRequest requestWithURL:
                       [NSURL URLWithString:@"http://www.google.nl"]]];

Reachability * reach = [Reachability reachabilityForInternetConnection];
UIImageView *RbackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image"]];
reach.reachableBlock = ^(Reachability * reachability)
{
    dispatch_async(dispatch_get_main_queue(), ^{

        [RbackgroundView removeFromSuperview];
    });
};

reach.unreachableBlock = ^(Reachability * reachability)
{
    dispatch_async(dispatch_get_main_queue(), ^{

        [self.webView addSubview:RbackgroundView];
        [self.webView bringSubviewToFront:RbackgroundView];
    });
};

[reach startNotifier];

}
Paulw11
  • 108,386
  • 14
  • 159
  • 186
Hanso0o
  • 3
  • 1

1 Answers1

0

You have also to check current NetworkStatus and update UI, along setting reachable/unreachable blocks. Note that you'll be notified when reachability changed, thereby when you launching with one status (for example without internet) reachability won't notify you until the status is changed to other. (turning on wifi). Here is code how will look like.

NetworkStatus internetStatus = [reach currentReachabilityStatus];
switch (internetStatus) {
    case NotReachable:
    {
        // update UI, for example [RbackgroundView removeFromSuperview];
    }
        break;
    case ReachableViaWiFi:
    {
        // update UI
    }
        break;
    case ReachableViaWWAN:
    {
        // update UI
    }
        break;
}
Seryozha
  • 1,649
  • 1
  • 14
  • 13
  • When I start the app with no connection it shows the image but when I reconnect internet it's stuck on a white screen. any suggestions ?(when It's connected and I remove the connection it works...) – Hanso0o May 23 '14 at 09:20
  • As I see, in that case your `reachableBlock` block executed and it seems ok. Where did you add answer code ? – Seryozha May 23 '14 at 11:52
  • Hey there I replaced the image with a html file and this is shown when its not reachable evreything works great and my app is in the store now – Hanso0o Jun 05 '14 at 12:32