A point to be aware of jscontext use in Ios7--javascriptcore

Source: Internet
Author: User

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 achieveNSURLConnectionDelegateNSURLConnectionDataDelegate .

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.