Re: Running JavaScript in iOS WebView.
Re: Running JavaScript in iOS WebView.
- Subject: Re: Running JavaScript in iOS WebView.
- From: glenn andreas <email@hidden>
- Date: Wed, 17 Nov 2010 16:12:36 -0600
On Nov 17, 2010, at 3:33 PM, Geoffrey Holden wrote:
> I've written an app for the Mac (which runs rather nicely) and now I'm trying to port it to iOS (where it won't run at all). The particular line of code which is causing a problem is this:
>
> [webView stringByEvaluatingJavaScriptFromString:cmdStr];
>
> cmdStr contains the following: rcs.invoke(dojo.fromJson('{"pw":"password","type":"signIn","email":"email@hidden"}'));
>
> I'm using the JSON framework on Google code (http://code.google.com/p/json-framework/), which (I'm assured) is iOS compatible. It certainly builds without trouble.
>
> The error I get when this line (fails to) execute is:
>
> void SendDelegateMessage(NSInvocation*): delegate (webViewDidLayout:) failed to return after waiting 10 seconds. main run loop mode: GSEventReceiveRunLoopMode
>
> I have got webViewDidFinishLoad (that's where this code is called) - so it isn't that it's trying to run on nothing.
>
> If you have any ideas about what I could do to fix this, I'd be most interested to hear them!
>
>From the documentation <http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html>:
JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script. This is likely to occur at a random place in your code, so unintended consequences may result. This limit is imposed because JavaScript execution may cause the main thread to block, so when scripts are running, the user is not able to interact with the webpage.
So one of your routines (I'm guessing rcs.invoke) is taking a long time (more than 10 seconds - perhaps it is waiting for some networked based action to complete). So if your JavaScript code is waiting for completion, you're going to have to refactor that code to work more asynchronously and not block.
Glenn Andreas email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden