I'm using xcode6 with ARC.
I have a login storyboard with login stuff. I have a login process wich a wish to run in background (other thread). So cool 'im using :
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Call Async URL
});
But i have some difficulties mostly because I'have to call multiple async URLs.
So no problem, I try to implement this:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Call Async URL withcallback block
// In block
dispatch_semaphore_signal(sema);
});
// Wait 30 seconds max to finish
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30*10^9));
sema = dispatch_semaphore_create(0);
// check if is ok to continue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Call Async URL withcallback block
// In block
dispatch_semaphore_signal(sema);
});
// Wait 30 seconds max to finish
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30*10^9));
});
Is it ok to do this or is there an other way ?
EDIT: I have to do much more that 2 calls and it would be a mess to recursive all my asynch call.