Skip to content

Instantly share code, notes, and snippets.

@cactis
Forked from markrickert/webview.m
Created April 8, 2014 03:53
Show Gist options
  • Save cactis/10088874 to your computer and use it in GitHub Desktop.
Save cactis/10088874 to your computer and use it in GitHub Desktop.
//Here's the same thing in Objective-C
#import "WebView.h"
@implementation WebView
@synthesize webView = _webView;
-(void) viewDidLoad
{
[super viewDidLoad];
UIWebView *webview = [[UIWebView alloc] init];
webview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:webview];
self.title = @"Web View";
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"WebView" ofType:@"html"];
[_webView loadHTMLString:[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil] baseURL:nil];
_webView.delegate = self;
}
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType
{
if ( inType == UIWebViewNavigationTypeLinkClicked )
{
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
@end
class WebViewController < UIViewController
def viewDidLoad
super
self.title = "Web View"
self.view = UIWebView.alloc.init
view.delegate = self
webviewContent = File.read(App.resources_path + "/WebView.html") #This requires Bubble-Wrap to be installed
self.view.loadHTMLString(aboutContent, baseURL:nil)
end
#Open UIWebView delegate links in Safari.
def webView(inWeb, shouldStartLoadWithRequest:inRequest, navigationType:inType)
if inType == UIWebViewNavigationTypeLinkClicked
UIApplication.sharedApplication.openURL(inRequest.URL)
false #don't allow the web view to load the link.
end
true #return true for local file loading.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment