Monday, March 14, 2011

JS to Obj-c and Objc to JS

search for text which you can to test against

- (BOOL)webView:(UIWebView *)localwebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

NSURL *url = [request URL];

NSString *path = [[request URL] path];

NSString *pathTrimmed = [path lastPathComponent];

NSLog(@"sfdf %@",url);

NSLog(@"path f %@",pathTrimmed);

if ([pathTrimmed isEqualToString:@"Reset"]) {

// Display alert
UIAlertView *alertb = [[UIAlertView alloc] initWithTitle:@"You want to Reset Data??" message:@"" delegate:self cancelButtonTitle:@"No" otherButtonTitles: @"YES",nil];
[alertb show];

[alertb release];
return NO;
return YES;


and then based on alert call JS Function defined in html page

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if(buttonIndex == 1) {

//NSLog(@" its done now uplaod data");
[localwebView stringByEvaluatingJavaScriptFromString:@"confirmation()"];

No comments: