Home

Awesome

FLWebView Build Status

Note: This repository was written in Objective-C. A Swift version is available here.

This is an example Xcode project demonstrating how to use WKWebView in iOS 8 with a UIWebView fallback for earlier versions of iOS. A full discussion of this code is available here. Basically, we created a protocol that unifies the functionality we'd like to have in a WebView, and then created categories that ensure we have the proper methods in our UIWebView and WKWebView classes.

These are used in the ViewController viewDidLoad method to create a web view and add it to the active view. The code checks for WKWebKit and, if present, uses WKWebView. If it's not there, it defaults to UIWebView.

Usage

This is an example project but you should be able to build and test it with little setup. Obviously, as this is an iOS project the following steps apply to OS X. Assuming you have Ruby you can install homebrew if you don't have it already (just enter this in the terminal):

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then you can install xctool, Facebook's neat open source Xcode build tool:

brew install xctool

After that, you can run the test.sh script to build and test:

sh test.sh

There you go! Of course, you can this in Xcode, but this setup is great if you want to do some continuous integration, as Travis already has xctool installed by default.

Notes

If you're getting code signing errors with an Objective-C project in Travis, make sure that your build script specifies -sdk iphonesimulator and -test-sdk iphonesimulator. Also, if your .travis.yml file targets the script you're using locally (in our case, .travis.yml specifies script: sh test.sh) it makes the debug process a bit simpler.

Tests

As the goal of this project was not to create an example of good iOS testing, the tests for this repository are very minimal and largely serve largely to verify that we can build and deploy the application without issue. There are some tests to verify that we can instantiate a web view, but these are not particularly robust. You can find good information on unit testing in iOS from Apple's iOS Developer Library here.

Tools

References

License

© 2014 Float. Shared under an MIT license. See license.md for details.