Skip to content

Alert

Presents an alert.

Use this to configure an alert presented modally or as a sheet. After configuring the alert, call presentAlert() or presentSheet() to present the alert. The two presentations methods will return a value which carries the index of the action that was selected when fulfilled.

title

Title displayed in the alert. Usually a short string.

title: string

message

Detailed message displayed in the alert.

message: string

-new Alert

Constructs a new alert.

new Alert()

-addAction

Adds an action to the alert.

Adds an action button to the alert. To check if an action was selected, you should use the first parameter provided when the promise returned by presentAlert() and presentSheet() is resolved.

addAction(title: string)

-addDestructiveAction

Adds a destructive action to the alert.

Destructive actions titles have a red text color, signaling that the action may modify or delete data.

addDestructiveAction(title: string)

-addCancelAction

Adds a cancel action to the alert.

Adds a cancel action to the alert. When a cancel action is selected the index provided by presentAlert() or presentSheet() will always be -1.

addCancelAction(title: string)

-addTextField

Adds a text field prompting for user input.

Adds a text field to the alert controller prompting for user input. Retrieve the value for the text field using textFieldValue() and supply the index of the text field. Indices for text fields are assigned in the same order as they are added to the alert starting at 0.

Text fields are not supported when using the sheet presentation.

addTextField(placeholder: string, text: string)

-addSecureTextField

Adds a secure text field prompting for user input.

Adds a secure text field to the alert controller prompting for user input. Values entered into a secure text field will be hidden behind dots. Retrieve the value for the text field using textFieldValue() and supply the index of the text field. Indices for text fields are assigned in the same order as they are added to the alert starting at 0.

addSecureTextField(placeholder: string, text: string)

-textFieldValue

Retrieves value of a text field.

Retrieves the value of a text field added using addTextField() or addSecureTextField(). Indices for text fields are assigned in the same order as they are added to the alert starting at 0.

textFieldValue(index: number): string

-present

Presents the alert modally.

This is a shorthand for presentAlert().

present(): Promise<number>

-presentAlert

Presents the alert modally.

presentAlert(): Promise<number>

-presentSheet

Presents the alert as a sheet.

presentSheet(): Promise<number>