Created
November 9, 2012 18:04
-
-
Save ChrisRisner/4047216 to your computer and use it in GitHub Desktop.
ios day 14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"LocalPage" ofType:@"html" inDirectory:nil]; | |
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; | |
//Append javascript | |
NSString *script = @"<script>alert(\"This is an alert!!\");</script>"; | |
htmlString = [htmlString stringByAppendingString:script]; | |
[self.webView loadHTMLString:htmlString baseURL:nil]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSURL *url = [[NSURL alloc] initWithString:@"http://chrisrisner.com"]; | |
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; | |
[self.webView loadRequest:request]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"LocalPage" ofType:@"html" inDirectory:nil]; | |
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; | |
[self.webView loadHTMLString:htmlString baseURL:nil]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1>Hello iOS!</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1>Hello iOS!</h1> | |
<input type='button' value="Do something in iOS" onclick='window.location="callmycode:cmd=showAlert&var=myVar"'/> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSURL *url = [[NSURL alloc] initWithString:@"http://chrisrisner.com"]; | |
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; | |
self.webView.scalesPageToFit = YES; | |
[self.webView loadRequest:request]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { | |
NSURL *URL = [request URL]; | |
if ([[URL scheme] isEqualToString:@"callmycode"]) { | |
NSString *urlString = [[request URL] absoluteString]; | |
NSArray *urlParts = [urlString componentsSeparatedByString:@":"]; | |
//check to see if we just got the scheme | |
if ([urlParts count] > 1) { | |
NSArray *parameters = [[urlParts objectAtIndex:1] componentsSeparatedByString:@"&"]; | |
NSString *methodName = [parameters objectAtIndex:0]; | |
NSString *variableName = [parameters objectAtIndex:1]; | |
NSString *message = [NSString stringWithFormat:@"Obj-c from js with methodname=%@ and variablename=%@", methodName, variableName]; | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Great" message:message delegate: self cancelButtonTitle: nil otherButtonTitles: @"OK",nil, nil]; | |
[alert show]; | |
} | |
} | |
return YES; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[self.webView stringByEvaluatingJavaScriptFromString:@"alert('Trigger the JS!');"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ViewController : UIViewController <UIWebViewDelegate> | |
@property (weak, nonatomic) IBOutlet UIWebView *webView; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"LocalPage" ofType:@"html" inDirectory:nil]; | |
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; | |
//Append javascript | |
//NSString *script = @"<script>alert(\"This is an alert!!\");</script>"; | |
//htmlString = [htmlString stringByAppendingString:script]; | |
self.webView.delegate = self; | |
[self.webView loadHTMLString:htmlString baseURL:nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment