Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run javascript without UIWebView possible?

Is it possible to run some javascript code (having perhaps an NSString as input) without using a UIWebView? I would like to run this code in a separate thread so UIWebView is not possible and I don't really want to render anything, just get back the results.

like image 672
user130444 Avatar asked Oct 15 '22 14:10

user130444


1 Answers

I have not tried this, but here is one idea:

Write code to allocate an empty UIWebView but doesn't add it as a subview anywhere, and just directly call - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script on your javascript.

Then use NSOperation to run that in parallel.

Any reason that might not work for you? I think it would avoid displaying anything for the UIWebView.

As a side note, I can't think of anything you can do in javascript that you can't do more quickly directly in Objective-C. Except maybe parsing javascript that you get externally, which may be considered a no-no by Apple, depending on the details.

Guessing at your goals: If you want to parse a JSON server reply, I recommend the json-framework library hosted on google code. It has a nice interface, and it is surprisingly easy to learn and integrate.

like image 53
Tyler Avatar answered Oct 19 '22 01:10

Tyler