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

后端 未结 10 2441
再見小時候
再見小時候 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条回答
  •  长情又很酷
    2020-11-29 16:48

    I used the great solution proposed from Robert Sanders: How can my iPhone Objective-C code get notified of Javascript errors in a UIWebView?

    That hook for webkit works fine also on iPhone. Instead of standard UIWebView I allocated derived MyUIWebView. I needed also to define hidden classes inside MyWebScriptObjectDelegate.h:

    @class WebView;
    @class WebFrame;
    @class WebScriptCallFrame;

    Within the ios sdk 4.1 the function:

    - (void)webView:(id)webView windowScriptObjectAvailable:(id)newWindowScriptObject 
    

    is deprecated and instead of it I used the function:

    - (void)webView:(id)sender didClearWindowObject:(id)windowObject forFrame:(WebFrame*)frame
    

    Also, I get some annoying warnings like "NSObject may not respond -windowScriptObject" because the class interface is hidden. I ignore them and it works nice.

提交回复
热议问题