Blocks retain variables they capture. You can take advantage of that behaviour, but you should understand what you're doing there:
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[av show];
dispatch_async(dispatch_queue_create("com.mycompany.myqueue", 0), ^{
sleep(5);
dispatch_async(dispatch_get_main_queue(), ^{
[av dismissWithClickedButtonIndex:0 animated:YES];
});
});
The sleep(5)
is just simulating your long running task.
Instead of using UIAlertView
, I'd consider using a library like this: https://github.com/jdg/MBProgressHUD