問題是我調用megnto api,但是當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 = "[email protected]";
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 = "[email protected]";
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 = "[email protected]";
message = 6tyrtyryrty;
name = "Kaitlyn Matheson";
"phone_no" = 564564;
"product_name" = Ottoman;
"product_options" = "";
"update_time" = "0000-00-00 00:00:00";
},
startSession實際顯示記錄什麼發生是的NSLog被調用之前做印刷迴應。如何解決這個problem.s
因爲它是在不同線程上運行的renewSession – 2013-05-03 12:59:56
爲什麼這條線被註釋掉了? – Undo 2013-05-03 13:00:00