I am currently programming an application for iOS using UIWebView. My goal is to show the php site (from my web server) using WebView. I am pretty good with HTMl, CSS, JS and PHP, but Object C is not my strength. However, I managed to implement everything, and now my goal (when iOS does not have an Internet connection) is to display a local file instead of a file on the server after an error warning. After using Google, I was able to do it myself, but not as a reserve.
Now it displays a warning, but after clicking the ok button, the user receives a blank page. Not very convenient :( In the local html file, I could implement a kind of βRefreshβ button. I would be very happy if you have a (better?) Solution. Thank you!
My system: Xcode 4.5.1 on OS X 10.8.2
ViewController.h
ViewController.m
#import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize webView; @synthesize loadingSign; -(void) webViewDidStartLoad:(UIWebView *)webView { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [self.loadingSign startAnimating]; self.loadingSign.hidden = NO; } -(void) webViewDidFinishLoad:(UIWebView *)webView { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [self.loadingSign stopAnimating]; self.loadingSign.hidden = YES; } -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { [self.loadingSign stopAnimating]; self.loadingSign.hidden = YES; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Keine Internetverbindung" message:@"Bitte verbinde dich mit dem Internet." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } - (void)loadSite { NSString *fullURL = @"http://website.com"; NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj]; webView.scrollView.bounces = NO; webView.delegate = self; } - (void)viewDidLoad { [super viewDidLoad];
source share