in auth/testapp/src/ios/ios_main.mm [120:165]
std::string ReadTextInput(const char *title, const char *message, const char *placeholder) {
assert(g_view_controller);
// This should only be called from a background thread, as it blocks, which will mess up the main
// thread.
assert(![NSThread isMainThread]);
g_view_controller.textEntryResult = nil;
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:@(title)
message:@(message)
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
textField.placeholder = @(placeholder);
}];
UIAlertAction *confirmAction = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) {
g_view_controller.textEntryResult = alertController.textFields.firstObject.text;
}];
[alertController addAction:confirmAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *_Nonnull action) {
g_view_controller.textEntryResult = @"";
}];
[alertController addAction:cancelAction];
[g_view_controller presentViewController:alertController animated:YES completion:nil];
});
while (true) {
// Pause a second, waiting for the user to enter text.
if (ProcessEvents(1000)) {
// If this returns true, an exit was requested.
return "";
}
if (g_view_controller.textEntryResult != nil) {
// textEntryResult will be set to non-nil when a dialog button is clicked.
std::string result = g_view_controller.textEntryResult.UTF8String;
g_view_controller.textEntryResult = nil; // Consume the result.
return result;
}
}
}