我想通过' NSString'作为下面方法中作为URLString的参数,我们该怎么做呢
-(void)makeServiceCallSuccess:(void (^)(NSDictionary *response))success
failure:(void (^)(NSError *error))failure {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:URLString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
response = (NSDictionary *)responseObject;
success(response);
NSLog(@"JSON: %@", response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(error);
NSLog(@"Error: %@", error);
}];
}
答案 0 :(得分:2)
只需在方法中添加参数,通常我们就像
一样-(void)makeServiceCallSuccessWithURLString:(NSString*)urlString withResponseHandler:(void (^)(NSDictionary *response))success
failure:(void (^)(NSError *error))failure
答案 1 :(得分:0)
没有wat可以在该方法中传递参数,您可以编辑它并添加参数或从aproperty中读取值
-(void)makeServiceCallSuccess:(void (^)(NSDictionary *response))success
failure:(void (^)(NSError *error))failure {
NSString* myString = self.myProperty;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:myString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
response = (NSDictionary *)responseObject;
success(response);
NSLog(@"JSON: %@", response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(error);
NSLog(@"Error: %@", error);
}];
}