Wow people here are quite derogatory! Instead of discussing technicals
about interpreted languages, most here simply jumped to the conclusion
that I hadn't thought about this process.
Defending my choice
---
OK so the reason the data is "HUGE" is because of the shear number of
users of the app. I couldn't afford to keep the app free if I had to
use an intermediate server. Also, just like Chris mentioned in his
case, the potential for the site shutting down your one big mammoth
connection is very high regardless of how friendly your relationship
is with the server. It also puts an extra breaking point to the
availability of the app. All show stoppers.
Server vs client parsing. If the server format changes, both solutions
break anyway. Responsiveness is much faster doing it client side than
doing it on a central server. So on a technical level, I don't see any
benefit to using a central intermediary when in reality that central
intermediary is just processing (not bandwidth or storage) the exact
same code (scraping html into json).
The only problem which has been alluded to, which is not a technical
problem, is the grey area about "downloaded code". I'm not going to
discuss this apart from acknowledging that it's grey. eg. safari is
doing almost nothing but "downloading code". Now I don't need a flame
war here, just want to talk to people who are willing to discuss
interpreted languages and their use in iOS. And even a week of
downtime when the server does change format while apple approve is
still better than making the app economically unfeasible and less
responsive.
Back on topic!
--
Thank you Oliver for that link! Debugging javascript was so painful
and if I had to do it again. The remote debugger looks "creative",
I'll give it a shot.
Thanks Nathan for that code. Being able to load a file directly is
much more efficient!
One thing that I had trouble with, although mostly a JS question than
Obj-C, how do I get the file loaded into the DOM object? I tried all
sorts of hoopla but everything failed. The closest I've seen involved
creating an iframe and then loading the JS into that. But because I'm
not familiar with traversing the DOM tree (and no debugging to help me
figure out my basic syntax mistakes) I abandoned doing it this time
around...
On May 16, 2:29 pm, Nathan de Vries <
nat...@atnan.com> wrote:
> On Tuesday, 15 May 2012 at 9:51 AM, Pork wrote:
> > So far, I'm pumping javascript via a UIWebView [self.webView
> > stringByEvaluatingJavaScriptFromString:script];
>
> > But so far it's been painful. Mostly because I'm not used to
> > javascript and there is no way to debug or log while it's running. In
> > fact a huge hurdle was even passing that data into that call in the
> > first place.
>
> The trick is to minimize the raw JavaScript you're attempting to pass over the bridge. A UIWebView can load any HTML, CSS, JavaScript etc. file from within the application bundle on the device, or anywhere in the Simulator. Loading your JS from the filesystem will make things much easier.
>
> To create a minimal bridge for loading JS, you can do this:
>
> - (void)webViewDidFinishLoad:(UIWebView *)webView {
> NSString *bridge = @""
> "var NDVWebViewBridge = {"
> "loadScriptURL: function(scriptURL) {"
> "var script = document.createElement('script');"
> "script.type = 'text/javascript';"
> "script.src = scriptURL;"
> "document.getElementsByTagName('head')[0].appendChild(script);"
> "}"
> "}";
>
> [webView stringByEvaluatingJavaScriptFromString:bridge];
> [webView stringByEvaluatingJavaScriptFromString:@"NDVWebViewBridge.loadScriptURL('fi le:///Users/pork/path/to/my.js')"];