Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For crashes, the first step is to use error messages and the debugger to figure out what call is causing the problem. If the problem is caused by an uncaught exception, read this Apple article on <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocExceptionHandling.html" rel="nofollow noreferrer">exception handling</a>. The specific answer really depends on your code and exactly what is causing the crash, so I won't speculate about a particular solution. </p> <p>As far as detecting server error response codes (such as 404), that's more specific to WebKit. I assume you're using <a href="http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebView_Class/" rel="nofollow noreferrer">UIWebView</a> on iPhone, and you've probably noticed that none of the primary methods return errors. This is because it uses a delegate model to report progress or errors asynchronously. (It makes sense because you don't want your UI code to be at the mercy of a slow-loading (or non-existent) webpage. To be notified of such errors, there are a few steps.</p> <ol> <li>Adopt the <a href="http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebViewDelegate_Protocol/" rel="nofollow noreferrer"><code>UIWebViewDelegate</code></a> protocol, usually in the same class that will start the webpage load for convenience.</li> <li>Set that object as the delegate of the UIWebView instance. (It has a <code>delegate</code> property, so you can use something like either <strong><code>uiView.delegate = self</code></strong> or <strong><code>[uiView setDelegate:self]</code></strong> based on what you prefer.)</li> <li>Implement the <a href="http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webView:didFailLoadWithError:" rel="nofollow noreferrer"><code>webView:didFailLoadWithError:</code></a> method in that class. (You can be notified when the load finishing by implementing <a href="http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webViewDidFinishLoad:" rel="nofollow noreferrer"><code>webViewDidFinishLoad:</code></a> as well.) This is where you include the logic of what should happen when an error occurs.</li> </ol> <p>I didn't see any detailed documentation on the content of any particular errors handed back via this delegate method, but it's a standard <a href="http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/" rel="nofollow noreferrer"><code>NSError</code></a> object, and I recommend checking out the contents by calling its methods, such as <code>-localizedDescription</code> and <code>-userInfo</code>.</p> <p>Here is some sample code with #import statements excluded for brevity.</p> <p><strong>MyClass.h</strong></p> <pre><code>@interface MyClass : NSObject &lt;UIWebViewDelegate&gt; { IBOutlet UIWebView* myWebView; } -(void)webView:(UIWebView*)webView didFailLoadWithError:(NSError *)error; @end </code></pre> <p><strong>MyClass.m</strong></p> <pre><code>@implementation MyClass - (id) init { if ((self = [super init]) == nil) return nil; // initialize myWebView myWebView.delegate = self; return self; } - (void) webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error { ... } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload