To be clear, even when the alert action handler doesn’t get called, we do see subsequent logging from other functions that run on the main thread, such as gesture handlers, applicationWillResignActive, etc. So we know that the main thread has not hung. Is this consistent with the other instances of this issue you’ve seen?
I will certainly use a callback if I have to. The alert presentation function is used in about a dozen different places; we’ve seen the uncalled handler problem only for the most frequently shown action sheet, but if I understand you correctly the same problem could occur anywhere the function is used.
The motivation for semaphores/polling was that, like the old NSAlert runModal function, it allows the caller to have straightforward linear code. (Using async/await was not an option because using Objective-C rather than Swift was a requirement of the project.)
A possibly related WWDC video says, “A common anti-pattern is trying to make an asynchronous API act synchronous by waiting on a semaphore. This should always be avoided on the main thread.”
https://developer.apple.com/videos/play/wwdc2021/10258?time=550
I thought this meant that the main thread should never wait on a semaphore. Should the main thread also never signal a semaphore, as in the alert case? What if both the waiting thread and the signaling thread are secondary threads? I’m asking because there are a few other places where our code uses a semaphore “to make an asynchronous API act synchronous,” always in an effort to allow linear code.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: