dispatch_asyncを順番に追加したいと思いますが、ランダムに起動しないようにしたいと思います。 例:以前の最初のdispatch_asyncが終了したときに、2番目のdispatch_asyncを実行する方法は?
ディスパッチ_アシンク1開始...
ディスパッチ_アシンク1が終了します。
ディスパッチ_アシンク2が開始...
ディスパッチ_アシンク2が終了します。
dispatch_async 3が開始...
dispatch_async 3が終了します。
事前に
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"%@",[connection currentRequest]);
NSLog(@"connectionDidFinishLoading");
NSError* error;
NSString *responseKey = [self getResponseKey:connection];
NSDictionary* response = [NSJSONSerialization JSONObjectWithData:[receivedData objectForKey:responseKey] options:kNilOptions error:&error];
//NSLog(@"%@", response);
if (error)
{
NSLog(@"Error: %@", error);
NSLog(@"Error: Response strange format, not an NSArray and not a NSString!\n%@", [[NSString alloc] initWithData:[receivedData objectForKey:responseKey] encoding:NSUTF8StringEncoding]);
}
NSLog(@"connection url : %@", connection.currentRequest.URL);
if ([[NSString stringWithFormat:@"%@", [connection currentRequest]] rangeOfString:@"getSynchroGuest?"].location != NSNotFound)
{
NSLog(@"response success");
if ([[response valueForKey:@"lignes"] isKindOfClass:[NSArray class]])
{
if ([[response valueForKey:@"lignes"] count] > 0)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
[self fillDataBaseWithDict:response];
nbTotal = nbTotal + PACKET_FOR_SYNC;
[self WebServiceSynchroGuest:self.activityIndicator withSynchroBtn:synchroBtn withNbTotal:nbTotal];
});
}
}
...
おかげで...私はsqliteのを更新する必要があり、最初のディスパッチ中の情報は、第二の発送のために必要です。
SOLUTION:
dispatch_async(serialDispatchQueue, ^{
[self fillDataBaseWithDict:response];
nbTotal = nbTotal + PACKET_FOR_SYNC;
dispatch_async(dispatch_get_main_queue(), ^(void){
[self WebServiceSynchroGuest:self.activityIndicator withSynchroBtn:synchroBtn withNbTotal:nbTotal];
});
});
dispatch_async 1の完了ブロック内にdispatch_async 2などを置くことができます。 –
これはconnectionDidFinishLoadingにありますので、私はWSを起動してディスパッチを開始する前に答えを待つ必要があります – Claudio
できます。完了ハンドラがある場合。ハンドラの最後の行に挿入するだけです。 –