How to enable WebGL in iOS 5.x UIWebView

In iOS HTML5 WebGL is currently not supported in Safari or when writing an iOS application using the UIWebView component. However, a workaround exists as WebGL support is available for iAd applications. The trick is (1) to extend/re-define the interface of UIWebView, (2) create a WebGL enabled UIWebView in your ViewController and (3) assign the custom view to your view controller.

(1) extend/re-define the interface of WebUIView (necessary for iOS5.x)
@interface UIWebView()

  • (void)_setWebGLEnabled:(BOOL)newValue; // workaround
    @end

(2) c...