Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>UPDATE: I have created a github repository to contain the latest code I am using. All changes will be posted there. <a href="https://github.com/Hackmodford/HMFJSONResponseSerializerWithData">https://github.com/Hackmodford/HMFJSONResponseSerializerWithData</a></p> <p>The answer comes from this issue on github. <a href="https://github.com/AFNetworking/AFNetworking/issues/1397">https://github.com/AFNetworking/AFNetworking/issues/1397</a></p> <p>gfiumara is the dev who came up with this. I have only slightly modified his subclass of AFJSONResponseSerializer to include an actual string instead of the NSData</p> <pre><code>//MSJSONResponseSerializerWithData.h #import "AFURLResponseSerialization.h" /// NSError userInfo key that will contain response data static NSString * const JSONResponseSerializerWithDataKey = @"JSONResponseSerializerWithDataKey"; @interface MSJSONResponseSerializerWithData : AFJSONResponseSerializer @end </code></pre> <hr> <pre><code>// MSJSONResponseSerializerWithData.m #import "MSJSONResponseSerializerWithData.h" @implementation MSJSONResponseSerializerWithData - (id)responseObjectForResponse:(NSURLResponse *)response data:(NSData *)data error:(NSError *__autoreleasing *)error { if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) { if (*error != nil) { NSMutableDictionary *userInfo = [(*error).userInfo mutableCopy]; userInfo[JSONResponseSerializerWithDataKey] = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSError *newError = [NSError errorWithDomain:(*error).domain code:(*error).code userInfo:userInfo]; (*error) = newError; } return (nil); } return ([super responseObjectForResponse:response data:data error:error]); } @end </code></pre> <p>Here is an example of how I use it in the failure block.</p> <pre><code>} failure:^(NSURLSessionDataTask *task, NSError *error) { NSLog(@"%@",[error.userInfo objectForKey:@"JSONResponseSerializerWithDataKey"]); }]; </code></pre>
    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.
    3. 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