Provides the editable content for a notification.
- iOS 10.0+
- tvOS 10.0+
- watchOS 3.0+
UNMutable object contains the data associated with a notification. You use the properties of this class to specify the parameters of a local notification, such as whether the notification adds a badge to the app’s icon, plays a notification sound, or displays an alert. You can also provide app-specific identifiers to help the system determine how to process the notification.
You use this class by creating an instance of it, configuring its properties, and assigning it to a
UNNotification object. Configuring a request object in this way creates a local notification for you to schedule. The trigger condition associated with the request object defines when the notification is delivered to the user. Listing 1 shows the creation of a content object whose notification displays an alert and plays a sound after a delay of five seconds. The strings for the alert are stored in the app’s
Localizable file using the specified keys and loaded just prior to displaying the alert.
Localizing the Alert Strings
The strings you display in a notification alert should be localized for the current user. Although you can use the
NSLocalized macros to load strings from your app’s resource files, a better option is to use the
localized method to specify the string. The
localized method delays the loading of the localized string until the notification is delivered. Thus, if the user changes language settings before a notification is delivered, the alert text is updated to the user’s current language instead of the language that was set when the notification was scheduled.