user1878200
user1878200

Reputation: 85

UIWebview javascript bridge

I am supposed to communicate between Objective C and javascript code, i also want to return objects from objective c to js and js back to objective c. For that I used a library called Webviewjavascriptbridge. But i could not get a return value from objective c to js. Can some one tell me if there is any other library that can achieve this? I tried with the libraries referred in this link iOS JavaScript bridge but i could not get a return value from objective c to js.

Upvotes: 2

Views: 8363

Answers (3)

Gon
Gon

Reputation: 1143

You want a return value from ObjC to js. Maybe that means your js code needs a parameter provided by ObjC code. Then you can try this:

NSString *returnValue = [self someMethod];
NSString *jsCallBack = [NSString stringWithFormat:@"yourJsMethodName:('%@')", returnValue];
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];

Is that what you want? I hope it helps.

Upvotes: 0

Abid Hussain
Abid Hussain

Reputation: 1549

JSBridge is an easy to use library to communicate between JS and cocoa/Objective-c`.

http://code.google.com/p/jsbridge-to-cocoa/

If you want to send a message to Javascript from app then UIWebView has a method for you. This is a code I implemented to assign filled data in webview to a Customer.

NSString *jsSave=[NSString stringWithFormat:@"set_customer(%@);",self.customer.customerId];
[webView stringByEvaluatingJavaScriptFromString:jsSave]; 

set_customer is the method of JS.

Upvotes: 3

Related Questions