NotificationCategories

@objc(UANotificationCategories)
public class NotificationCategories : NSObject

Utility methods to create categories from plist files or dictionaries.

Notification Categories Factories

  • Factory method to create the default set of user notification categories. Background user notification actions will default to requiring authorization.

    Declaration

    Swift

    @objc
    public class func defaultCategories() -> Set<UNNotificationCategory>

    Return Value

    A set of user notification categories

  • Factory method to create the default set of user notification categories.

    Declaration

    Swift

    @objc
    public class func defaultCategories(withRequireAuth requireAuth: Bool)
        -> Set<UNNotificationCategory>

    Parameters

    requireAuth

    If background actions should default to requiring authorization or not.

    Return Value

    A set of user notification categories.

  • Creates a set of categories from the specified .plist file.

    Categories are defined in a plist dictionary with the category ID followed by an array of user notification action definitions. The action definitions use the same keys as the properties on the action, with the exception of “foreground” mapping to either UIUserNotificationActivationModeForeground or UIUserNotificationActivationModeBackground. The required action definition title can be defined with either the “title” or “title_resource” key, where the latter takes precedence. If “title_resource” does not exist, the action definition title will fall back to the value of “title”. If the required action definition title is not defined, the category will not be created.

    Example:

    { “category_id” : [ { “identifier” : “action ID”, “title_resource” : “action title resource”, “title” : “action title”, “foreground” : true, “authenticationRequired” : false, “destructive” : false }] }

    Declaration

    Swift

    @objc
    public class func createCategories(fromFile path: String) -> Set<
        UNNotificationCategory
    >

    Parameters

    path

    The path of the plist file

    Return Value

    A set of categories

  • Creates a user notification category with the specified ID and action definitions.

    Declaration

    Swift

    @objc
    public class func createCategory(
        _ categoryId: String,
        actions actionDefinitions: [[AnyHashable: Any]]
    ) -> UNNotificationCategory?

    Parameters

    categoryId

    The category identifier

    actionDefinitions

    An array of user notification action dictionaries used to construct UNNotificationAction for the category.

    Return Value

    The user notification category created, or nil if an error occurred.

  • Creates a user notification category with the specified ID, action definitions, and hiddenPreviewsBodyPlaceholder.

    Declaration

    Swift

    @objc
    public class func createCategory(
        _ categoryId: String,
        actions actionDefinitions: [[AnyHashable: Any]],
        hiddenPreviewsBodyPlaceholder: String
    ) -> UNNotificationCategory?

    Parameters

    categoryId

    The category identifier

    actionDefinitions

    An array of user notification action dictionaries used to construct UNNotificationAction for the category.

    hiddenPreviewsBodyPlaceholder

    A placeholder string to display when the user has disabled notification previews for the app.

    Return Value

    The user notification category created or nil if an error occurred.