iOS Class - JJGWebView

JJGWebView - iPhone ScreenshotFor the first few months of my time developing iPhone apps, one of the essential building blocks of most of my apps was a UIWebView—basically, I wanted to be able to open links in-app, rather than open links in Safari (which basically boots the user out of my app—not usually a good thing).

Seeing that there are very disparate articles and postings on the Internet concerning the building of said in-app browsers, I thought I'd develop a class/XIB for iOS that I could reuse across all my apps, rather than build an app-specific browser each time I build a new app.

I haven't seen any other well-documented drop-in UIWebView classes, so I built my own, and tossed it up on GitHub. There may be a rough edge or two, but I've made it pretty painless to be able to integrate JJGWebView (my in-app browser class) with any iPhone App. In fact, I'm using it now on the Catholic STL App, and the Catholic News Live app (among others).

Download the class (+demo) on GitHub:
JJGWebView on GitHub

Details

This class/view came about as a result of my wanting to follow best practices for an intuitive in-app browser—one that doesn't have all the functionality of Safari (since that's not needed), but has enough functionality so someone might justifiably stay in your app to follow a thread of links, rather than switch to Safari.

The class also references ShareKit (SHK), which allows for easy sharing of links through various services, or opening links in Safari, or emailing links. Read more about ShareKit here.

Implementation

It's simple to use JJGWebView in your app. Here is a quick run-through:

  1. Download the entire project from GitHub.
  2. Open JJGWebView.xcodeproj in Xcode.
  3. Drag the 'JJGWebView' group into your own project's "Groups & Files" (in Xcode).
  4. Drag the 'ShareKit' group into your own project's "Groups & Files" (in Xcode).
  5. Optionally (recommended) follow ShareKit's instructions for configuring it to your tastes.
  6. Implement JJGWebView in your own class; all you have to do is send over a link and a title (or just a link), like so:

In your implementation file, wherever you'd like to push over to the web view (works best inside a Navigation Controller-based app or view), put this at the top, under any other #import statements:

#import "JJGWebView.h"

Then, use this code in your method where someone selects a link (in the demo app, you can see this code in the didSelectRowAtIndexPath method of our table view—you could also use for calloutAccessoryTapped, in a map view):

// Open link in JJGWebView.
JJGWebView *webViewToPush = [[JJGWebView alloc] initWithNibName:@"JJGWebView" bundle:nil];
webViewToPush.title = @"NSString Title Here";
webViewToPush.webViewURL = [NSURL URLWithString:@"http://www.example.com/"];
[self.navigationController pushViewController:jjgWebView animated:YES]; // Push to the web view.
[jjgWebView release]; // Release the web view.

This should push your view controller over to the web view, and everything should work fine from there.

If you're having trouble getting this working, check out the code in JJGWebViewViewController.m. Everything's in there, and it's set up as a very basic UITableView.

Bug Reports? Feature Requests?

If you find any bugs, have any patches, or want to see something that's not in JJGWebView, please file issues on the GitHub project page: JJGWebView Issues.