Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When using RestKit 0.10 you can use the given delegate method <code>objectLoaderDidLoadUnexpectedResponse</code>.</p> <pre><code>- (void)objectLoaderDidLoadUnexpectedResponse:(RKObjectLoader *)objectLoader { if ([[objectLoader response] statusCode] == 403) { // Your action here } } </code></pre> <p>In RestKit 0.20 you can use a response descriptor for a single code or a set of codes.</p> <pre><code>RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping pathPattern:nil keyPath:@"yourKeyPath" statusCodes:[NSIndexSet indexSetWithIndex:403]]; </code></pre> <p>More status code sets in the <a href="http://restkit.org/api/0.20.0/Classes/RKObjectManager.html" rel="nofollow">documentation</a>.</p> <h2>Update</h2> <p>When using your BaseViewController for handling the errors of the request made in one of the other view controllers, you can set up notifications.</p> <p><em>BaseViewController</em></p> <pre><code>- (void)viewDidLoad { // ... // Set observer for notification e.g. "requestFailedWith403Error" [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handle403Error:) name:@"requestFailedWith403Error" object:self]; } - (void)handle403Error:(NSNotification)notification { // Code for handling the error } </code></pre> <p><em>SubViewController</em></p> <pre><code>- (void)loginToServer { // ... // Set authorization header [[RKObjectManager sharedManager].HTTPClient setAuthorizationHeaderWithUsername:@"username" password:@"password"]; // e.g. POST to server [[RKObjectManager sharedManager] postObject:yourObject path:@"path/toserver" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { // Handling success } failure:^(RKObjectRequestOperation *operation, NSError *error) { // Handling error with notification [[NSNotificationCenter defaultCenter] postNotificationName:@"requestFailedWith403Error" object:self]; }]; } </code></pre> <p>Too optimize your central configuration with the handling of errors you can have another look at the example code given in the <a href="https://github.com/RestKit/RestKit#centralize-configuration-in-an-object-manager" rel="nofollow">RestKit Wiki</a> (where the error mapping is added).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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