iosafnetworking

AFNetworking returning NSCFData; issue with registerHTTPOperationClass


I am new to AFNetworking and am making a call to a simple login api that returns json like:

{"status":"success","data":{"auth_token":"12jt34"}}

I'm doing it via the following but it is returning __NSCFData rather than something that I can manipuate.

NSURL *baseURL = [NSURL URLWithString:@"http://localhost:3000/arc/v1/api/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient defaultValueForHeader:@"Accept"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        uname,@"email", pwd, @"password",
                        nil];
[httpClient postPath:@"login-mobile" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSString *className = NSStringFromClass([responseObject class]);
    NSLog(@"val: %@",className);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error retrieving data: %@", error);
}];

and it outputs:

2013-03-21 14:52:51.290 FbTabbed[21505:11303] val: __NSCFData

but I'd like it for it to be a dictionary that I can manipulate which is how I think it is supposed to work? What am I doing wrong?


Solution

  • [httpClient defaultValueForHeader:@"Accept"];
    

    should be:

    [httpClient setDefaultHeader:@"Accept" value:@"application/json"];