I need to encapsulate the response from AFNetworking calls within my own method as I'm writing a library. This code gets me close:
MyDevice *devices = [[MyDevice alloc] init];
[devices getDevices:@"devices.json?user_id=10" success:^(AFHTTPRequestOperation *operation, id responseObject) {
... can process json object here ...
}
- (void)getDevices:(NSString *)netPath success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
[[MyApiClient sharedDeviceServiceInstance] getPath:[NSString stringWithFormat:@"%@", netPath]
parameters:nil success:success failure:failure];
}
However, I need to process the json object data returned from getPath before returning to getDevices(). I've tried this:
- (void)getDevices:(NSString *)netPath success:(void (^)(id myResults))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
[[MyApiClient sharedDeviceServiceInstance] getPath:[NSString stringWithFormat:@"%@", netPath]
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
... can process json object here ...
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
... process errors here ...
}];
}
But now there is no call back to getDevices(). So how do I process the json object in getDevices & have the block return on completion? Appreciate the help, as I'm new to blocks.