在编写库时,我需要将来自 AFNetworking 调用的响应封装在我自己的方法中。这段代码让我很接近:
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];
}
但是,我需要在返回 getDevices() 之前处理从 getPath 返回的 json 对象数据。我试过这个:
- (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 ...
}];
}
但是现在没有回调 getDevices()。那么如何处理 getDevices 中的 json 对象并在完成时返回块?感谢您的帮助,因为我是块新手。