On Jun 17, 2008, at 11:47 AM, Thomas Okken wrote:
I have a method that I'm going to call from JavaScript:
- (NSString *) methodToBeCalledFromJavaScript: (NSString *) someArg
callback: (WebScriptObject *) callback
{
JSObjectRef fn = [callback JSObject];
//...do lengthy task in a background thread...
//...rejoin foreground thread...
JSValueRef result = JSObjectCallAsFunction(ctx, fn, nil, argc,
argv, nil);
//...clean up...
}
And I'll use it from JavaScript like this:
function callback(foo, bar, baz)
{
//...display results in web page...
}
someButton.onclick =
"theObj.methodToBeCalledFromJavaScript("Hello!", callback);"
Does that look right?
Yes.
I'm a bit confused about the [callback JSObject] call -- I don't see
a method named JSObject in the WebScriptObject reference.
It's new, so it might not be in an older reference.
Also, the JavaScriptCore reference mentions header files like
<JavaScriptCore/JSBase.h> which I can't find on my system, even
though I have the latest iPhone SDK installed. Is this a separate
download?
You should have these latest JavaScriptCore headers on your computer
if you're developing using the OS X 10.5 SDK or on 10.5 using the
system headers.
-- Darin