gpt4 book ai didi

iphone - 识别当前到达的响应的请求对象restkit v0.20

转载 作者:行者123 更新时间:2023-11-29 04:02:21 24 4
gpt4 key购买 nike

我正在对同一服务进行两次后期调用,如何识别随各自请求到达的响应。

req1 = post {"status" = "1"} 
req2 = post {"status" = "0"}

response {"data" = "xxx"}
response {"data" = "yyy"}

如何识别 req1 和 req2 的响应。我正在使用restkit v0.20。

-(void)fetchCoursesWithToken:(NSString *)token  courseType:(NSInteger)courseType{
AppSettings *settings = [AppSettings sharedAppSettings];
NSString *userCourseServiceURL = settings.getCoursesURL;

RKObjectManager *manager = [RKObjectManager sharedManager];

[settings showActivityIndicatorWithMessage:@""];



CourseRequest *reqObj = [CourseRequest new];
reqObj.loginToken = token;
reqObj.courseType = [NSString stringWithFormat:@"%d",courseType];







RKManagedObjectRequestOperation *operation = [manager appropriateObjectRequestOperationWithObject:reqObj method:RKRequestMethodPOST path:userCourseServiceURL parameters: nil];

[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[settings removeActivityIndicator];

NSHTTPURLResponse *response = [[operation HTTPRequestOperation] response]; //operation is an RKObjectRequestOperation

NSDictionary *headerDictionary = [response allHeaderFields];

NSString *status = [headerDictionary objectForKey:@"X-NTST-Request-Status"];

if ([status isEqualToString:@"ERR"]) {
NSString *errorMessage = [headerDictionary objectForKey:@"X-NTST-Request-Note"];
NSLog(@"Error Occured :%@",errorMessage);
}
else if ([status isEqualToString:@"WARN"]) {
NSString *errorMessage = [headerDictionary objectForKey:@"X-NTST-Request-Note"];
NSLog(@"Error Occured :%@",errorMessage);
}
if ([status isEqualToString:@"OK"]) {
NSLog(@"Succes status:%@",status);
arr = [[NSMutableArray alloc] initWithArray:[mappingResult array]];
[self.delegate responseArrived:arr];
}



} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"It Failed: %@", error);
[settings removeActivityIndicator];
}];
[RKObjectManager.sharedManager enqueueObjectRequestOperation:operation];
}

我正在调用同一个函数来自 View Controller

 [self.service fetchCoursesWithToken:@"ds"    courseType:0 ];


[self.service fetchCoursesWithToken:@"ds" courseType:1 ];

当响应到达时,我有回调委托(delegate)来查看 Controller 。因为我使用相同的函数响应回调到同一 block 。

最佳答案

Restkit 是基于 block 的,因此当您发出请求时,您可以传递一个 block (实际上是两个,一个表示成功,一个表示失败),以便在响应到来时执行。

由于 block 与各个请求相关联,因此无需区分。

关于iphone - 识别当前到达的响应的请求对象restkit v0.20,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15698661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com