CFRunLoopRun() to use for Universal App

In my app, I need to show some choices to the user to select, wait for the response, then handle it accordingly. I know UIAlertController with UIAlertAction can do this and I'm using it mostly, but I have some cases they don’t fit and I must handle manually.

To achieve this, I’m using:

Code Block language
CFRunLoopRef currentRunLoop;
~ ~ ~ ~ ~ 
currentRunLoop = CFRunLoopGetCurrent();
CFRunLoopRun(); 

Wait for the user response here,
then, when the selection is made,

Code Block language
CFRunLoopStop(currentRunLoop);

will be executed within its call back to exit CFRunLoop() to do further handlings written after it.

Now, this has been working just fine on iPhone, iPad (and those simulators) on different generations, but when I run this on MyMac (designed for iPad), it just keeps going without stopping at CFRunLoopRun().

I assume this is supposed to work on any platform under “Universal” concept…. 
Or is there anything I’m missing or misunderstanding? 

Replies

In my app, I need to show some choices to the user to select, wait for
the response, then handle it accordingly.

This is not supported on any of our platforms. Honestly, it’s surprising that you’ve got this far.

Or is there anything I’m … misunderstanding?

Indeed there is. It’s simply not safe to run the main thread’s run loop recursively in the default run loop mode, which is what you’re doing. Clearly iOS is more tolerant of this than macOS, but this technique is fundamentally broken. You need to rethink your approach.

In UIKit there’s no safe way to present a UI and then block waiting for a response [1]. You must present the UI and return to the event loop, and then pick things up when the user makes their choice.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

[1] Ironically, AppKit actually supports this because it has a long history of implementing modal dialogs this way.
Thank you very much for the reply although it was a very bad news for me....

Just to let you know, I learned this Modal structure 10 years ago and has been used in my app since then.
It's been working just fine until I discovered this.
So sad to know it was an "illegal" technique....