问题是我调用 megnto api 但是当 api 在执行所有其他语句之前返回对象时。
NSMutableArray *list=[Magento.service startSession];
NSLog(@"Record is:%@",list);
我修改的 startSession 方法是:
- (NSMutableArray *)startSession
{
NSString *_sessionID;
NSNumber *nsPage =[NSNumber numberWithInt:1];
NSNumber *nsData =[NSNumber numberWithInt:10];
NSMutableArray *listOfName = [[NSMutableArray alloc] init];
NSArray *args = [NSArray arrayWithObjects:nsPage,nsData,nil ];
@synchronized(self) {
_sessionID = sessionID;
}
if (_sessionID != FAILED_SESSION)
dispatch_group_enter(session_group);
[client postPath:@"login" parameters:@{@"username": MAGENTO_USERNAME, @"apiKey": MAGENTO_API_KEY} success:^(AFHTTPRequestOperation *operation, id responseObject) {
sessionID = responseObject;
dispatch_group_leave(session_group);
[client postPath:@"call" parameters:@{@"sessionId":sessionID, @"resourcePath":@"callforprice_collection.getCallForPriceCollection",
@"args":args
} success:^(AFHTTPRequestOperation *operationData, id responseData) {
NSLog(@"Response : %@",responseData);
[listOfName addObject:[responseData valueForKey:@"name"]];
} failure:^(AFHTTPRequestOperation *operationData, NSError *error) {
NSLog(@"Response is not get");
sessionID = FAILED_SESSION;
}];
NSLog(@"got session %@", sessionID);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
sessionID = FAILED_SESSION;
}];
return listOfName;
}
o/p 是
2013-05-03 06:27:16.272 CallForPrice[3120:c07] Record is: ()
2013-05-03 06:27:19.836 CallForPrice[3120:c07] got session 88ef34087a12809334ae3a0c839f85b6
** response that i have printed in method**
2013-05-03 06:27:22.048 CallForPrice[3120:c07] Response : (
{
"callforprice_id" = 13;
country = Austria;
"created_time" = "2013-05-03 12:03:05";
emailid = "indies.tester@gmail.com";
message = hfhftrfygjh;
name = "Richard Conover";
"phone_no" = 8977896;
"product_name" = Ottoman;
"product_options" = "";
"update_time" = "0000-00-00 00:00:00";
},
{
"callforprice_id" = 12;
country = "Antigua and Barbuda";
"created_time" = "2013-05-03 12:01:24";
emailid = "indies.tester@gmail.com";
message = sdfsdfsdfwe;
name = "Richard Conover";
"phone_no" = 5645;
"product_name" = Ottoman;
"product_options" = "";
"update_time" = "0000-00-00 00:00:00";
},
{
"callforprice_id" = 11;
country = Angola;
"created_time" = "2013-05-03 11:58:51";
emailid = "indies.tester@gmail.com";
message = 6tyrtyryrty;
name = "Kaitlyn Matheson";
"phone_no" = 564564;
"product_name" = Ottoman;
"product_options" = "";
"update_time" = "0000-00-00 00:00:00";
},
startSession 正在显示实际发生的记录是在调用 do response 之前打印 NSLOG 。如何解决这个问题.s