ContentBundle demo updated

I’ve updated the demo app for the ContentBundle application. The application now presents a UIWebView showing HTML from the ZIP file.

An Update button causes the app to reach out to the server and reload the page.

The screenshots below show the app before and after updating:

The app is fairly simple. We wired up the RootViewController to use a UIWebView, and wired up the Update button all in Interface Builder.

In viewDidLoad we load the initial content:

- (void)viewDidLoad
    [super viewDidLoad];
    SSContentBundle* provider = [SSContentBundle mainBundle];
    NSString* docPath = [provider pathForFile:@"index.html"];
    NSLog(@"Path to index.html: %@", docPath);
    NSURL* url = [NSURL fileURLWithPath:docPath];
    NSURLRequest* request = [NSURLRequest requestWithURL:url];
    UIWebView* webView = (UIWebView*)self.view;
    [webView loadRequest:request];

When the Update button is clicked we perform the update:

- (IBAction)performUpdate:(id)sender
    SSContentBundle* provider = [SSContentBundle mainBundle];
    self.navigationItem.rightBarButtonItem.enabled = NO;
    [provider checkForUpdatesWithCompletionHandler:^(BOOL updateFound, NSError *error)
         self.navigationItem.rightBarButtonItem.enabled = YES;
             NSLog(@"Error removing old content: %@", [error localizedDescription]);
             UIAlertView* alert;
             alert = [[UIAlertView alloc] initWithTitle:@"Content Test"
                                                message:[error localizedDescription]
             [alert show];
             [alert release];
             // refresh the browser...
             UIWebView* webView = (UIWebView*)self.view;
             [webView reload];

That’s about it… The server content has different HTML, and includes an image to prove that we can reference other files – they’re all just expanded onto the file system after all.

The changes are already live on github:

Leave a Reply