누군가가 도와 줄 수 있습니까?블록 완료시기를 알아 보는 방법
약 1000 개의 데이터 항목이 포함 된 NSMutablearray가 있습니다.
내가 원하는 것은 이러한 항목을 하나씩 차례로 보내고 HTTP 요청을 사용하여 서버로 보냅니다.
그러나 그 중요한 내가 한 번에 하나씩 보내, 그래서 내가 이상적으로 수행 할 작업을 다음 의사 코드
for(int i =0; i < array.count; i++)
{
[ServerLayer ServerUploadRow:[array objectAtIndex:i] : ^void (int ReturnValue, BOOL err){
if(err == true)
{
//Do some local stuff here.
}
}];
}
을 가지고 다음
for(int i =0; i < array.count; i++)
{
//Wait here till i know that we not waiting on a block to complete
[ServerLayer ServerUploadRow:[array objectAtIndex:i] : ^void (int ReturnValue, BOOL err){
if(err == true)
{
//Do some local stuff here.
//Signify that we done
}
}];
}
같은 것을 가지고있다 ServerUploadRow 함수는 HTTP 명령을 전송합니다. 당신이이 작업을 시작 했죠
- (void)initiateRequestNumber:(NSInteger)index
{
[ServerLayer ServerUploadRow:array[index] : ^(int ReturnValue, BOOL err){
if (err == true) {
//Do some local stuff here.
} else {
NSInteger nextIndex = index + 1;
if (nextIndex < array.count) {
[self initiateRequestNumber:nextIndex];
} else {
// do whatever you want now that everything is done
}
}
}];
}
그리고 : 비동기 ServerUploadRow
실행, 당신은 요청을 할 수 있다고 가정
감사
[sendSynchronousRequest] (https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/index.html#//apple_ref/occ/clm/NSURLConnection)해야합니다./sendSynchronousRequest : returningResponse : 오류 :) –