Posts

Post not yet marked as solved
9 Replies
I tried your code and the same thing happens, the function returns before the alert is shown, and the alert is displayed after that. When the user presses either button, the application freezes.Might be due to the fact that this function is called from inside another dispatch:> dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{...Edit: after trying on a new app and using the above additional dispatch async to wrap it I confirmed that it does work on a void function, but when the function returns a value, it always happens before the block is executed.
Post not yet marked as solved
9 Replies
Sorry, I meant to say "void" but the corrector changed it to "voice".I ran your code on a new app trying to create a similar solution to what I have in mine: making the function return a bool value and wrapping the function call in a dyspatch_async like the one in my previous comment. And it does work as expected, which means there is something else in my app that is causing this. Maybe it´s the deadlock situation you described above. Thank you for helping me clear this out, I will report back when I find the problem.
Post not yet marked as solved
9 Replies
Also, if I use dispatch_async and the semaphore, the app freezes the moment the user hits the yes/no button, it never reaches the AlertAction.
Post not yet marked as solved
9 Replies
If I only use dispatch_sync it does not achieve the result I want, the function returns before the block is executed.I think this happens because this function is called from a thread that´s not the main one.Here´s the code below, when I put breakpoints, it executes in the following order:1. Block (presentViewController)2. function returns with result = NO3. Alert appears on screen.4. User presses Yes/No5. Executes AlertActionAt this point, since the function has already returned, it does not achieve the expected result.__block BOOL result = NO;// dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_sync(dispatch_get_main_queue(), ^{ UIViewController *rootController = [IOSUtil visibleViewController]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[self getResourceText:caption] message:[self getResourceText:message] preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:cancelButtonText style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { [LayoutIOS internalShowProgressControl];// dispatch_semaphore_signal(semaphore); }]]; [alertController addAction:[UIAlertAction actionWithTitle:okButtonText style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { result = YES; [LayoutIOS internalShowProgressControl];// dispatch_semaphore_signal(semaphore); }]]; [LayoutIOS internalHideProgressControl]; [rootController presentViewController:alertController animated:YES completion:nil]; }); // dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); return result;
Post not yet marked as solved
9 Replies
I was not the one who wrote the initial code, but from what I understand, the issue is that this method is originally called from another thread, several steps away:> dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{...And since what I need is to do is show an AlertView and wait for the user input, it needs to be done in the main thread, correct?
Post not yet marked as solved
4 Replies
Were you able to find a solution?I am having a similar issue where the app freezes when I show an AlertController inside a dispatch_group, only happens when using Xcode11.