How can my iPhone Objective-C code get notified of Javascript errors in a UIWebView?

后端 未结 10 2427
再見小時候
再見小時候 2020-11-29 16:31

I need to have my iPhone Objective-C code catch Javascript errors in a UIWebView. That includes uncaught exceptions, syntax errors when loading files, undefined variable re

10条回答
  •  萌比男神i
    2020-11-29 16:48

    I have created an SDK kosher error reporter that includes:

    1. The error message
    2. The name of the file the error happens in
    3. The line number the error happens on
    4. The JavaScript callstack including parameters passed

    It is part of the QuickConnectiPhone framework available from the sourceForge project

    There is even an example application that shows how to send an error message to the Xcode terminal.

    All you need to do is to surround your JavaScript code, including function definitions, etc. with try catch. It should look like this.

    try{
    //put your code here
    }
    catch(err){
        logError(err);
    }
    

    It doesn't work really well with compilation errors but works with all others. Even anonymous functions.

    The development blog is here is here and includes links to the wiki, sourceForge, the google group, and twitter. Maybe this would help you out.

提交回复
热议问题