UIAlertController with many lines fails on macOS Ventura (Catalyst)

Hi all

When running the following code on macOS Ventura, I get the error below: (At least in a Catalyst app running on macOS.)

Code to reproduce:

NSString *message = @"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20";

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:message preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
[alert addAction:yesAction];

UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
[alert addAction:noAction];

[self presentViewController:alert animated:YES completion:nil];

Error:

[Layout] Unable to simultaneously satisfy constraints:

(
    "<NSLayoutConstraint:0x60000265caa0 _NSAlertContentView:0x7fc0600390a0.trailingMargin == NSTextField:0x7fc06003a900.trailing   (active)>",
    "<NSLayoutConstraint:0x60000265c9b0 _NSAlertImageView:0x7fc06003a460.leading == _NSAlertContentView:0x7fc0600390a0.leadingMargin   (active)>",
    "<NSLayoutConstraint:0x60000265ca50 H:[_NSAlertImageView:0x7fc06003a460]-(10)-[NSTextField:0x7fc06003a900]   (active)>",

    "<NSLayoutConstraint:0x60000265ca00 _NSAlertImageView:0x7fc06003a460.width == 64   (active)>"

)

Will attempt to recover by breaking constraint 

<NSLayoutConstraint:0x60000265ca50 H:[_NSAlertImageView:0x7fc06003a460]-(10)-[NSTextField:0x7fc06003a900]   (active)>

It looks like the error happens as soon as the message is displayed with scrollbar on older macOS versions.

Add a Comment

Replies

Sorry not to help, there may be an internal limit to alerts. Usually, alerts are not done to display 20 lines of text.

  • Sorry, but your answer is useless. I just wanted to share a found issue with macOS Ventura. This still works fine on iOS an older macOS, but freezes the app on macOS Ventura.

Add a Comment

Try it with 19 lines, then 18, then 17 etc. When you hit a number of lines where the error doesn't appear, you'll know that alerts can only have that number of lines.

I really wouldn't have an alert with that many lines in; I'd display a modal view instead with all the text on it, and a couple of buttons at the bottom.

In the mean time I also opened an Apple DTS ticket with my sample code above and thy confirmed that it is an Apple bug and I should file a bug report.

BTW: It seems to be also an issue with a long message and not only with a message containing many \n. --> https://stackoverflow.com/questions/74256830/multi-line-uialertcontroller-freezes-on-macos-ventura