PDA

View Full Version : bridging javascript events to obj-c - performance




seggenhuber
Mar 7, 2009, 05:56 PM
Hi!

I'm developing for iphone and android using phonegap. ( http://phonegap.com )
my app needs some objective-c <-> Javascript bridging to pass gestureevents
back and forth, because i need certain obj-c code to do effects when a user has
clicked on a certain html element.

what i found out so far is that the method of using
document.location="gap:command:params" for executing native code from
javascript is very very slow. (e.g. my obj-c code gets called once a
second)
has anyone made any *different experiences?
is there some way to speed this technique up in a serious way?

my 2nd approach is to "inject" a JS object und funcs from obj-c
with stringByEvaluatingJavaScriptFromString , push js-event data into
an JS array
and read that data back form obj-c via [self performSelector:@selector
(readJavascriptLogger) withObject:nil afterDelay:0.1] every 0.1 secs
as described here in the 1st comment:
http://drnicwilliams.com/2008/11/10/to-webkit-or-not-to-webkit-within-your-iphone-app/
this works a lot better, but still is not as fast as i would like it
to be.
does this technique has some serious drawbacks?
is there any better way to this kind of javscriptEvent->objc bridging?
is there any way to generally boost JS performance on the iphone?

your help is much appreciated!
sam