Instance Property

showsSuppressionButton

Specifies whether the alert includes a suppression checkbox, which you can employ to allow a user to opt out of seeing the alert again.

Declaration

@property BOOL showsSuppressionButton;

Discussion

The default value of this property is NO, which specifies the absence of a suppression checkbox in the alert. Set the value to YES to show a suppression checkbox in the alert.

By default, a suppression checkbox has the title, “Do not show this message again.” To customize it, use the checkbox’s title property, as follows:

myAlert.suppressionButton.title = @"Do not show this warning again";

To create an alert that responds to the selection state of the suppression checkbox, use code like that shown in Listing 1. Figure 1 shows the corresponding alert.

Listing 2

Creating an alert with a suppression checkbox

NSString *alertSuppressionKey = @"AlertSuppression";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 
if ([defaults boolForKey: alertSuppressionKey]) {
    NSLog (@"Alert suppressed");
} else {
    NSAlert *anAlert = [[NSAlert alloc] init];
    anAlert.messageText = @"Message text.";
    anAlert.informativeText = @"Informative text.";
    anAlert.showsSuppressionButton = YES; // Uses default checkbox title
    [anAlert runModal];
    if (anAlert.suppressionButton.state == NSOnState) {
        // Suppress this alert from now on
        [defaults setBool: YES forKey: alertSuppressionKey];
    }
}
Figure 1

Alert with a suppression checkbox and customized text

See Also

Displaying Alerts

- runModal

Runs the alert as an app-modal dialog and returns the constant that identifies the button clicked.

- beginSheetModalForWindow:completionHandler:

Runs the alert modally as a sheet attached to the specified window.

- beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:

Runs the alert modally as an alert sheet attached to a specified window.

Deprecated
suppressionButton

The alert’s suppression checkbox.