In a company project, the use of Highchart to do chart display components, which will use the JavaScriptCore, the code is not, say the principle.
The requirement is that the data in the server CSV format is requested via HTTP, then parsed, and then displayed in the HTML with Highchart in the last incoming local.
Due to the need to display loading,progress and so on, so the use of iOS provided by native nsurlconnection, to achieveNSURLConnectionDelegate 和 NSURLConnectionDataDelegate .
The original design is this, in the Controller view implementation <UIWebViewDelegate>, in the viewdidload load the local HTML file (this is the HTML to display the chart, All that is needed for the chart to be configured, just wait for OC data to come in, initialize the Jscontext in -webviewdidfinishload: and start the connection request. In -connectiondidfinishloading: The data pain over [jscontext[@ "value" callwitharguments:]] to the use of the JS method.
In doing so, the chart can come out occasionally and more often throw exception. Exception there are two, one is: exc_bad_access code=1 address=**** Another is: exc_breakpoint (code=exc_i386_bpt subcode=0x0) .
Start to suspect is the problem of data, the network request to the data stored locally, and then in -webviewdidfinishload: through the jscontext to JS, the result is completely no problem, the chart every time display perfect.
By searching, the error is learned in StackOverflow:exc_bad_access code=1 address=**** is the result of using an object that has already been release. Through debug, trace to the time when the problem is called JS method. Because the project uses arc, and our server is placed on AWS, and the registered region is Ireland, the server response time generally in 2~5s, (slower, because the background needs to calculate), I think, is not in the waiting time, OC has put my jscontext Release, because I was in -webviewdidfinishload: Initialize the Jscontext object and start requesting data, that is, the Jscontext object is at least idle for 2~5s time.
Begin to modify the code, start the request data in viewdidload , wait for the request to complete after the load local HTML, and then in -webviewdidfinishload: Re- initialize the Jscontext, and pass the data over [jscontext[@ "value" callwitharguments:]] , run ... Everything is fine.
Arc is really a lot of convenience for us, and perhaps we should be aware of its greatest benefits while enjoying it.
A point to be aware of jscontext use in Ios7--javascriptcore