Using the JSContext
from a UIWebView
I have created a javascript function that is implemented as an Objective C block:
JSContext *js =
After a couple days looking at stack traces of threads waiting for each other, the solution was so simple I'm not surprised I overlooked it in favor of trying more complicated stuff.
If you want to call back into a UIWebView
's javascript asynchronously, use window.setTimeout
and let the JSVirtualMachine
take care of queuing the callback.
Just replace
dispatch_async(dispatch_get_main_queue(), ^{
[self.callback callWithArguments:@[arg]];
});
with
dispatch_async(dispatch_get_main_queue(), ^{
[self.callback.context[@"setTimeout"] callWithArguments:@[self.callback, @0, arg]];
});