I need a really modal alert, i.e., one which runs and allows the user interaction and closes and returns the selected option inside of a single method.
(I need to serve an API which calls my callback, presuming I show an alert, get the user's decision, and return it from that very callback. The callback comes in the main thread.)
What's the proper way to do this in i(Pad)OS 18+? Thanks!
For reference, up to 17, the following code worked nicely; in 18, it does not anymore:
volatile BOOL __block stillRuns=YES;
UIAlertController* ac=[UIAlertController alertControllerWith... preferredStyle:UIAlertControllerStyleAlert];
[ac addAction:[UIAlertAction actionWith... handler:^(UIAlertAction * _Nonnull action) {
stillRuns=NO;
}]];
...
[UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:ac animated:YES completion:nil];
while (stillRuns) [NSRunLoop.currentRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:.1]];
What you are trying to do is not supported, and did not work on all hardware that ran iOS 17 either. The reason why it has stopped working more widely on iOS 18 is because the behaviors that prevent it from working have been enabled on a wider range of hardware on iOS 18.
Apple's UI Frameworks do not support a general means of presenting UI that blocks execution until a response from the user is delivered. You will need to refactor your application to handle this kind of response asynchronously instead.