Why when using GCD, UIAlertController display is delayed or not shown?

62 Views Asked by At

I have this code, which gets called from another class like this:

    //  send message not to turn off machine and display network indicator
[cm displayAlert: @"Warning" andData: @"Database restore is about to begin; DO NOT turn iPad OFF during restore!" andTag:0 andViewController:self];

and this is the code:

#pragma mark -  displayAlert
- (void) displayAlert: (NSString *)alertTitle andData: (NSString *) alertMessage andTag: (int) tag andViewController: vc  {

UIAlertController *alertController = [UIAlertController
                                      alertControllerWithTitle:alertTitle
                                      message:alertMessage
                                      preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
                               style:UIAlertActionStyleCancel
                               handler:^(UIAlertAction *action)
                               {
                                   NSLog(@"Cancel action");
                               }];

UIAlertAction *okAction = [UIAlertAction
                           actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction *action)
                           {
                               NSLog(@"OK action");
                           }];

[alertController addAction:cancelAction];
[alertController addAction:okAction];

dispatch_async(dispatch_get_main_queue(), ^{
  [vc presentViewController:alertController animated:YES completion:nil];
});
}

The problem is that the presentation is either delayed or not shown at all. I used the GCD code which many, if not all, of the examples on SO show... what could be causing this delay?

0

There are 0 best solutions below