usernotifications

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package usernotifications provides Go bindings for the UserNotifications framework.

Push user-facing notifications to the user’s device from a server, or generate them locally from your app.

User-facing notifications communicate important information to users of your app, regardless of whether your app is running on the user’s device. For example, a sports app can let the user know when their favorite team scores. Notifications can also tell your app to download information and update its interface. Notifications can display an alert, play a sound, or badge the app’s icon.

Essentials

  • User Notifications updates: Learn about important changes in User Notifications.
  • Asking permission to use notifications: Request permission to display alerts, play sounds, or badge the app’s icon in response to a notification.

Notification management

Remote notifications

  • Setting up a remote notification server: Generate notifications and push them to user devices.
  • Sending push notifications using command-line tools: Use basic macOS command-line tools to send push notifications to Apple Push Notification service (APNs).
  • Testing notifications using the Push Notification Console: Send test notifications and access delivery logs to test your app’s integration with Apple Push Notification service (APNs).

Notification requests

  • Scheduling a notification locally from your app: Create and schedule notifications from your app when you want to get the user’s attention.
  • UNNotificationRequest: A request to schedule a local notification, which includes the content of the notification and the trigger conditions for delivery.
  • UNNotification: The data for a local or remote notification the system delivers to your app.

Push notifications in Safari

  • Sending web push notifications in web apps and browsers: Update your web server and website to send push notifications that work in Safari, other browsers, and web apps, following cross-browser standards.

Notification content

  • Implementing communication notifications: Configure and display your app’s communication notifications by using intents.
  • UNNotificationContentProviding: A protocol the system uses to provide context relevant to user notifications.
  • UNNotificationActionIcon: An icon associated with an action.
  • UNMutableNotificationContent: The editable content for a notification. (UNNotificationInterruptionLevel)
  • UNNotificationContent: The uneditable content of a notification. (UNNotificationInterruptionLevel)
  • UNNotificationAttachment: A media file associated with a notification.
  • UNNotificationSound: The sound played upon delivery of a notification.
  • UNNotificationSoundName: A string providing the name of a sound file.

Triggers

  • UNCalendarNotificationTrigger: A trigger condition that causes a notification the system delivers at a specific date and time.
  • UNTimeIntervalNotificationTrigger: A trigger condition that causes the system to deliver a notification after the amount of time you specify elapses.
  • UNLocationNotificationTrigger: A trigger condition that causes the system to deliver a notification when the user’s device enters or exits a geographic region you specify.
  • UNPushNotificationTrigger: A trigger condition that indicates Apple Push Notification Service (APNs) has sent the notification.
  • UNNotificationTrigger: The common behavior for subclasses that trigger the delivery of a local or remote notification.

Notification categories and user actions

  • Declaring your actionable notification types: Differentiate your notifications and add action buttons to the notification interface.
  • UNNotificationCategory: A type of notification your app supports and the custom actions that the system displays. (UNNotificationCategoryOptions)
  • UNNotificationAction: A task your app performs in response to a notification that the system delivers. (UNNotificationActionOptions)
  • UNTextInputNotificationAction: An action that accepts user-typed text.

Notification responses

  • Handling notifications and notification-related actions: Respond to user interactions with the system’s notification interfaces, including handling your app’s custom actions.
  • UNNotificationResponse: The user’s response to an actionable notification.
  • UNTextInputNotificationResponse: The user’s response to an actionable notification, including any custom text that the user typed or dictated.

Notification service app extension

  • Modifying content in newly delivered notifications: Modify the payload of a remote notification before it’s displayed on the user’s iOS device.
  • UNNotificationServiceExtension: An object that modifies the content of a remote notification before it’s delivered to the user.

Entitlements

  • APS Environment Entitlement: The environment for push notifications.
  • APS Environment (macOS) Entitlement: The environment for push notifications in macOS apps.

Sample code

  • Handling Communication Notifications and Focus Status Updates: Create a richer calling and messaging experience in your app by implementing communication notifications and Focus status updates.
  • Implementing Alert Push Notifications: Add visible alert notifications to your app by using the UserNotifications framework.
  • Implementing Background Push Notifications: Add background notifications to your app by using the UserNotifications framework.

Classes

  • UNNotificationAttributedMessageContext

Key Types

Code generated from Apple documentation. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var (
	// UNErrorDomain is the error domain for notifications.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNErrorDomain
	UNErrorDomain string
	// UNNotificationAttachmentOptionsThumbnailClippingRectKey is the clipping rectangle for a thumbnail image.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachmentOptionsThumbnailClippingRectKey
	UNNotificationAttachmentOptionsThumbnailClippingRectKey string
	// UNNotificationAttachmentOptionsThumbnailHiddenKey is a Boolean value indicating whether the system hides the attachment’s thumbnail.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachmentOptionsThumbnailHiddenKey
	UNNotificationAttachmentOptionsThumbnailHiddenKey string
	// UNNotificationAttachmentOptionsThumbnailTimeKey is the frame number of an animation to use as a thumbnail image.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachmentOptionsThumbnailTimeKey
	UNNotificationAttachmentOptionsThumbnailTimeKey string
	// UNNotificationAttachmentOptionsTypeHintKey is a hint about an attachment’s file type.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachmentOptionsTypeHintKey
	UNNotificationAttachmentOptionsTypeHintKey string
	// UNNotificationDefaultActionIdentifier is an action that indicates the user opened the app from the notification interface.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationDefaultActionIdentifier
	UNNotificationDefaultActionIdentifier string
	// UNNotificationDismissActionIdentifier is the action that indicates the user explicitly dismissed the notification interface.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationDismissActionIdentifier
	UNNotificationDismissActionIdentifier string
)

Functions

func NewBoolErrorBlock

func NewBoolErrorBlock(handler BoolErrorHandler) (objc.ID, func())

NewBoolErrorBlock wraps a Go BoolErrorHandler as an Objective-C block. The caller must defer the returned cleanup function.

Used by:

func NewErrorBlock

func NewErrorBlock(handler ErrorHandler) (objc.ID, func())

NewErrorBlock wraps a Go ErrorHandler as an Objective-C block. The caller must defer the returned cleanup function.

Used by:

func NewUNNotificationContentBlock

func NewUNNotificationContentBlock(handler UNNotificationContentHandler) (objc.ID, func())

NewUNNotificationContentBlock wraps a Go UNNotificationContentHandler as an Objective-C block. The caller must defer the returned cleanup function.

Used by:

func NewUNNotificationPresentationOptionsBlock

func NewUNNotificationPresentationOptionsBlock(handler UNNotificationPresentationOptionsHandler) (objc.ID, func())

NewUNNotificationPresentationOptionsBlock wraps a Go UNNotificationPresentationOptionsHandler as an Objective-C block. The caller must defer the returned cleanup function.

Used by:

  • [UNUserNotificationCenterDelegate.UserNotificationCenterWillPresentNotificationWithCompletionHandler]

func NewUNNotificationSettingsBlock

func NewUNNotificationSettingsBlock(handler UNNotificationSettingsHandler) (objc.ID, func())

NewUNNotificationSettingsBlock wraps a Go UNNotificationSettingsHandler as an Objective-C block. The caller must defer the returned cleanup function.

Used by:

func NewVoidBlock

func NewVoidBlock(handler VoidHandler) (objc.ID, func())

NewVoidBlock wraps a Go VoidHandler as an Objective-C block. The caller must defer the returned cleanup function.

Used by:

  • [UNUserNotificationCenterDelegate.UserNotificationCenterDidReceiveNotificationResponseWithCompletionHandler]

Types

type BoolErrorHandler

type BoolErrorHandler = func(bool, error)

BoolErrorHandler handles The block to execute asynchronously with the results.

  • granted: A Boolean value indicating whether the person grants authorization. The value of this parameter is [true](<doc://com.apple.documentation/documentation/Swift/true>) when the person grants authorization for one or more options. The value is [false](<doc://com.apple.documentation/documentation/Swift/false>) when the person denies authorization or authorization is undetermined. Use [getNotificationSettings(completionHandler:)](<doc://com.apple.usernotifications/documentation/UserNotifications/UNUserNotificationCenter/getNotificationSettings(completionHandler:)>) to check the authorization status.
  • error: An object containing error information or `nil` if no error occurs.

The error can be type-asserted to *foundation.NSError for Domain, Code, and UserInfo.

Used by:

type ErrorHandler

type ErrorHandler = func(error)

ErrorHandler handles The handler to execute after the update finishes.

  • error: An error object indicating whether a problem occurred. If the notification was scheduled successfully, this parameter is `nil`; otherwise, it is set to an error object indicating the reason for the failure.

The error can be type-asserted to *foundation.NSError for Domain, Code, and UserInfo.

Used by:

type IUNCalendarNotificationTrigger

type IUNCalendarNotificationTrigger interface {
	IUNNotificationTrigger

	// The next date at which the trigger conditions are met.
	NextTriggerDate() foundation.INSDate
	// The date components to construct this object.
	DateComponents() foundation.NSDateComponents
}

An interface definition for the UNCalendarNotificationTrigger class.

Getting the Trigger Information

  • [IUNCalendarNotificationTrigger.NextTriggerDate]: The next date at which the trigger conditions are met.
  • [IUNCalendarNotificationTrigger.DateComponents]: The date components to construct this object.

See: https://developer.apple.com/documentation/UserNotifications/UNCalendarNotificationTrigger

type IUNNotification

type IUNNotification interface {
	objectivec.IObject

	// The notification request containing the payload and trigger condition for the notification.
	Request() IUNNotificationRequest
	// The delivery date of the notification.
	Date() foundation.INSDate

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotification class.

Getting the Notification Details

  • [IUNNotification.Request]: The notification request containing the payload and trigger condition for the notification.
  • [IUNNotification.Date]: The delivery date of the notification.

See: https://developer.apple.com/documentation/UserNotifications/UNNotification

type IUNNotificationAction

type IUNNotificationAction interface {
	objectivec.IObject

	// The unique string that your app uses to identify the action.
	Identifier() string
	// The localized string to use as the title of the action.
	Title() string
	// The icon associated with the action.
	Icon() IUNNotificationActionIcon

	// The behaviors associated with the action.
	Options() UNNotificationActionOptions

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationAction class.

Getting Information

  • [IUNNotificationAction.Identifier]: The unique string that your app uses to identify the action.
  • [IUNNotificationAction.Title]: The localized string to use as the title of the action.
  • [IUNNotificationAction.Icon]: The icon associated with the action.

Getting Options

  • [IUNNotificationAction.Options]: The behaviors associated with the action.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction

type IUNNotificationActionIcon

type IUNNotificationActionIcon interface {
	objectivec.IObject

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationActionIcon class.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationActionIcon

type IUNNotificationAttachment

type IUNNotificationAttachment interface {
	objectivec.IObject

	// A hint about an attachment’s file type.
	UNNotificationAttachmentOptionsTypeHintKey() string
	// A Boolean value indicating whether the system hides the attachment’s thumbnail.
	UNNotificationAttachmentOptionsThumbnailHiddenKey() string
	// The clipping rectangle for a thumbnail image.
	UNNotificationAttachmentOptionsThumbnailClippingRectKey() string
	// The frame number of an animation to use as a thumbnail image.
	UNNotificationAttachmentOptionsThumbnailTimeKey() string

	// The unique identifier for the attachment.
	Identifier() string
	// The URL of the file for this attachment.
	URL() foundation.INSURL
	// The UTI type of the attachment.
	Type() string

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationAttachment class.

Creating an Attachment

  • [IUNNotificationAttachment.UNNotificationAttachmentOptionsTypeHintKey]: A hint about an attachment’s file type.
  • [IUNNotificationAttachment.UNNotificationAttachmentOptionsThumbnailHiddenKey]: A Boolean value indicating whether the system hides the attachment’s thumbnail.
  • [IUNNotificationAttachment.UNNotificationAttachmentOptionsThumbnailClippingRectKey]: The clipping rectangle for a thumbnail image.
  • [IUNNotificationAttachment.UNNotificationAttachmentOptionsThumbnailTimeKey]: The frame number of an animation to use as a thumbnail image.

Getting the Attachment Contents

  • [IUNNotificationAttachment.Identifier]: The unique identifier for the attachment.
  • [IUNNotificationAttachment.URL]: The URL of the file for this attachment.
  • [IUNNotificationAttachment.Type]: The UTI type of the attachment.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachment

type IUNNotificationCategory

type IUNNotificationCategory interface {
	objectivec.IObject

	// The unique string assigned to the category.
	Identifier() string
	// The actions to display when the system delivers notifications of this type.
	Actions() []UNNotificationAction
	// The intents related to notifications of this category.
	IntentIdentifiers() []string
	// The placeholder text to display when the system disables notification previews for the app.
	HiddenPreviewsBodyPlaceholder() string
	// A format string for the summary description used when the system groups the category’s notifications.
	CategorySummaryFormat() string

	// Options for how to handle notifications of this type.
	Options() UNNotificationCategoryOptions

	// The identifier of the notification’s category.
	CategoryIdentifier() string
	SetCategoryIdentifier(value string)
	// The action performs a destructive task.
	Destructive() UNNotificationActionOptions
	SetDestructive(value UNNotificationActionOptions)
	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationCategory class.

Getting the Information

  • [IUNNotificationCategory.Identifier]: The unique string assigned to the category.
  • [IUNNotificationCategory.Actions]: The actions to display when the system delivers notifications of this type.
  • [IUNNotificationCategory.IntentIdentifiers]: The intents related to notifications of this category.
  • [IUNNotificationCategory.HiddenPreviewsBodyPlaceholder]: The placeholder text to display when the system disables notification previews for the app.
  • [IUNNotificationCategory.CategorySummaryFormat]: A format string for the summary description used when the system groups the category’s notifications.

Getting the Options

  • [IUNNotificationCategory.Options]: Options for how to handle notifications of this type.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory

type IUNNotificationContent

type IUNNotificationContent interface {
	objectivec.IObject

	// The localized text that provides the notification’s primary description.
	Title() string
	// The localized text that provides the notification’s secondary description.
	Subtitle() string
	// The localized text that provides the notification’s main content.
	Body() string

	// The visual and audio attachments to display alongside the notification’s main content.
	Attachments() []UNNotificationAttachment
	// The custom data to associate with the notification.
	UserInfo() foundation.INSDictionary

	// The number that your app’s icon displays.
	Badge() foundation.NSNumber
	// The value your app uses to determine which scene to display to handle the notification.
	TargetContentIdentifier() string

	// The sound that plays when the system delivers the notification.
	Sound() IUNNotificationSound
	// The notification’s importance and required delivery timing.
	InterruptionLevel() UNNotificationInterruptionLevel
	// The score the system uses to determine if the notification is the summary’s featured notification.
	RelevanceScore() float64
	// The criteria the system evaluates to determine if it displays the notification in the current Focus.
	FilterCriteria() string

	// The identifier that groups related notifications.
	ThreadIdentifier() string
	// The identifier of the notification’s category.
	CategoryIdentifier() string
	// The text the system adds to the notification summary to provide additional context.
	SummaryArgument() string
	// The number the system adds to the notification summary when the notification represents multiple items.
	SummaryArgumentCount() uint

	// Returns a copy of the notification that includes content from the specified provider.
	ContentByUpdatingWithProviderError(provider UNNotificationContentProviding) (IUNNotificationContent, error)

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationContent class.

Accessing the primary content

  • [IUNNotificationContent.Title]: The localized text that provides the notification’s primary description.
  • [IUNNotificationContent.Subtitle]: The localized text that provides the notification’s secondary description.
  • [IUNNotificationContent.Body]: The localized text that provides the notification’s main content.

Accessing supplementary content

  • [IUNNotificationContent.Attachments]: The visual and audio attachments to display alongside the notification’s main content.
  • [IUNNotificationContent.UserInfo]: The custom data to associate with the notification.

Reading app configuration

  • [IUNNotificationContent.Badge]: The number that your app’s icon displays.
  • [IUNNotificationContent.TargetContentIdentifier]: The value your app uses to determine which scene to display to handle the notification.

Reading system configuration

  • [IUNNotificationContent.Sound]: The sound that plays when the system delivers the notification.
  • [IUNNotificationContent.InterruptionLevel]: The notification’s importance and required delivery timing.
  • [IUNNotificationContent.RelevanceScore]: The score the system uses to determine if the notification is the summary’s featured notification.
  • [IUNNotificationContent.FilterCriteria]: The criteria the system evaluates to determine if it displays the notification in the current Focus.

Retrieving group information

  • [IUNNotificationContent.ThreadIdentifier]: The identifier that groups related notifications.
  • [IUNNotificationContent.CategoryIdentifier]: The identifier of the notification’s category.
  • [IUNNotificationContent.SummaryArgument]: The text the system adds to the notification summary to provide additional context.
  • [IUNNotificationContent.SummaryArgumentCount]: The number the system adds to the notification summary when the notification represents multiple items.

Updating the notification’s content

  • [IUNNotificationContent.ContentByUpdatingWithProviderError]: Returns a copy of the notification that includes content from the specified provider.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent

type IUNNotificationRequest

type IUNNotificationRequest interface {
	objectivec.IObject

	// The unique identifier for this notification request.
	Identifier() string
	// The content associated with the notification.
	Content() IUNNotificationContent
	// The conditions that trigger the delivery of the notification.
	Trigger() IUNNotificationTrigger

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationRequest class.

Getting the Request Details

  • [IUNNotificationRequest.Identifier]: The unique identifier for this notification request.
  • [IUNNotificationRequest.Content]: The content associated with the notification.
  • [IUNNotificationRequest.Trigger]: The conditions that trigger the delivery of the notification.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationRequest

type IUNNotificationResponse

type IUNNotificationResponse interface {
	objectivec.IObject

	// The identifier string of the action that the user selected.
	ActionIdentifier() string
	// The notification to which the user responded.
	Notification() IUNNotification
	// An action that indicates the user opened the app from the notification interface.
	UNNotificationDefaultActionIdentifier() string
	// The action that indicates the user explicitly dismissed the notification interface.
	UNNotificationDismissActionIdentifier() string

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationResponse class.

Getting the Response Information

  • [IUNNotificationResponse.ActionIdentifier]: The identifier string of the action that the user selected.
  • [IUNNotificationResponse.Notification]: The notification to which the user responded.
  • [IUNNotificationResponse.UNNotificationDefaultActionIdentifier]: An action that indicates the user opened the app from the notification interface.
  • [IUNNotificationResponse.UNNotificationDismissActionIdentifier]: The action that indicates the user explicitly dismissed the notification interface.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationResponse

type IUNNotificationServiceExtension

type IUNNotificationServiceExtension interface {
	objectivec.IObject

	// Asks you to make any needed changes to the notification and notify the system when you’re done.
	DidReceiveNotificationRequestWithContentHandler(request IUNNotificationRequest, contentHandler UNNotificationContentHandler)
	// Tells you that the system is terminating your extension.
	ServiceExtensionTimeWillExpire()
}

An interface definition for the UNNotificationServiceExtension class.

Processing Notifications

  • [IUNNotificationServiceExtension.DidReceiveNotificationRequestWithContentHandler]: Asks you to make any needed changes to the notification and notify the system when you’re done.
  • [IUNNotificationServiceExtension.ServiceExtensionTimeWillExpire]: Tells you that the system is terminating your extension.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationServiceExtension

type IUNNotificationSettings

type IUNNotificationSettings interface {
	objectivec.IObject

	// The app’s ability to schedule and receive local and remote notifications.
	AuthorizationStatus() UNAuthorizationStatus

	// The setting that indicates whether your app’s notifications appear in Notification Center.
	NotificationCenterSetting() UNNotificationSetting
	// The setting that indicates whether your app’s notifications appear on a device’s Lock screen.
	LockScreenSetting() UNNotificationSetting
	// The authorization status for displaying alerts.
	AlertSetting() UNNotificationSetting
	// The setting that indicates whether badges appear on your app’s icon.
	BadgeSetting() UNNotificationSetting
	// The authorization status for playing sounds for incoming notifications.
	SoundSetting() UNNotificationSetting
	// The authorization status for playing sounds for critical alerts.
	CriticalAlertSetting() UNNotificationSetting
	// The setting that indicates the system schedules the notification.
	ScheduledDeliverySetting() UNNotificationSetting
	// The setting that indicates the system treats the notification as time-sensitive.
	TimeSensitiveSetting() UNNotificationSetting

	// The type of alert that the app may display when the device is unlocked.
	AlertStyle() UNAlertStyle
	// The setting that indicates whether the app shows a preview of the notification’s content.
	ShowPreviewsSetting() UNShowPreviewsSetting
	// A Boolean value indicating the system displays a button for in-app notification settings.
	ProvidesAppNotificationSettings() bool

	DirectMessagesSetting() UNNotificationSetting

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationSettings class.

Getting the Authorization Status

  • [IUNNotificationSettings.AuthorizationStatus]: The app’s ability to schedule and receive local and remote notifications.

Getting Device-Specific Settings

  • [IUNNotificationSettings.NotificationCenterSetting]: The setting that indicates whether your app’s notifications appear in Notification Center.
  • [IUNNotificationSettings.LockScreenSetting]: The setting that indicates whether your app’s notifications appear on a device’s Lock screen.
  • [IUNNotificationSettings.AlertSetting]: The authorization status for displaying alerts.
  • [IUNNotificationSettings.BadgeSetting]: The setting that indicates whether badges appear on your app’s icon.
  • [IUNNotificationSettings.SoundSetting]: The authorization status for playing sounds for incoming notifications.
  • [IUNNotificationSettings.CriticalAlertSetting]: The authorization status for playing sounds for critical alerts.
  • [IUNNotificationSettings.ScheduledDeliverySetting]: The setting that indicates the system schedules the notification.
  • [IUNNotificationSettings.TimeSensitiveSetting]: The setting that indicates the system treats the notification as time-sensitive.

Getting Interface Settings

  • [IUNNotificationSettings.AlertStyle]: The type of alert that the app may display when the device is unlocked.
  • [IUNNotificationSettings.ShowPreviewsSetting]: The setting that indicates whether the app shows a preview of the notification’s content.
  • [IUNNotificationSettings.ProvidesAppNotificationSettings]: A Boolean value indicating the system displays a button for in-app notification settings.

Instance Properties

  • [IUNNotificationSettings.DirectMessagesSetting]

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings

type IUNNotificationSound

type IUNNotificationSound interface {
	objectivec.IObject

	// The sound that plays when the system delivers the notification.
	Sound() IUNNotificationSound
	SetSound(value IUNNotificationSound)
	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationSound class.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound

type IUNNotificationTrigger

type IUNNotificationTrigger interface {
	objectivec.IObject

	// A Boolean value indicating whether the system reschedules the notification after it’s delivered.
	Repeats() bool

	EncodeWithCoder(coder foundation.INSCoder)
}

An interface definition for the UNNotificationTrigger class.

Configuring the Trigger’s Behavior

  • [IUNNotificationTrigger.Repeats]: A Boolean value indicating whether the system reschedules the notification after it’s delivered.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationTrigger

type IUNPushNotificationTrigger

type IUNPushNotificationTrigger interface {
	IUNNotificationTrigger

	// The conditions that trigger the delivery of the notification.
	Trigger() IUNNotificationTrigger
	SetTrigger(value IUNNotificationTrigger)
}

An interface definition for the UNPushNotificationTrigger class.

See: https://developer.apple.com/documentation/UserNotifications/UNPushNotificationTrigger

type IUNTextInputNotificationAction

type IUNTextInputNotificationAction interface {
	IUNNotificationAction

	// The localized title of the text input button that the system displays to the user.
	TextInputButtonTitle() string
	// The placeholder text that the system localizes and displays in the text input field.
	TextInputPlaceholder() string
}

An interface definition for the UNTextInputNotificationAction class.

Getting Information

  • [IUNTextInputNotificationAction.TextInputButtonTitle]: The localized title of the text input button that the system displays to the user.
  • [IUNTextInputNotificationAction.TextInputPlaceholder]: The placeholder text that the system localizes and displays in the text input field.

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationAction

type IUNTextInputNotificationResponse

type IUNTextInputNotificationResponse interface {
	IUNNotificationResponse

	// The text response provided by the user.
	UserText() string
}

An interface definition for the UNTextInputNotificationResponse class.

Getting the Text Response

  • [IUNTextInputNotificationResponse.UserText]: The text response provided by the user.

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationResponse

type IUNTimeIntervalNotificationTrigger

type IUNTimeIntervalNotificationTrigger interface {
	IUNNotificationTrigger

	// The next date at which the trigger conditions are met.
	NextTriggerDate() foundation.INSDate
	// The time interval to create the trigger.
	TimeInterval() float64
}

An interface definition for the UNTimeIntervalNotificationTrigger class.

Getting the Trigger Information

  • [IUNTimeIntervalNotificationTrigger.NextTriggerDate]: The next date at which the trigger conditions are met.
  • [IUNTimeIntervalNotificationTrigger.TimeInterval]: The time interval to create the trigger.

See: https://developer.apple.com/documentation/UserNotifications/UNTimeIntervalNotificationTrigger

type IUNUserNotificationCenter

type IUNUserNotificationCenter interface {
	objectivec.IObject

	// Retrieves the authorization and feature-related settings for your app.
	GetNotificationSettingsWithCompletionHandler(completionHandler UNNotificationSettingsHandler)
	// Updates the badge count for your app’s icon.
	SetBadgeCountWithCompletionHandler(newBadgeCount int, completionHandler ErrorHandler)

	// Requests a person’s authorization to allow local and remote notifications for your app.
	RequestAuthorizationWithOptionsCompletionHandler(options UNAuthorizationOptions, completionHandler BoolErrorHandler)

	// The notification center’s delegate.
	Delegate() UNUserNotificationCenterDelegate
	SetDelegate(value UNUserNotificationCenterDelegate)
	// A Boolean value that indicates whether the device supports notification content extensions.
	SupportsContentExtensions() bool

	// Schedules the delivery of a local notification.
	AddNotificationRequestWithCompletionHandler(request IUNNotificationRequest, completionHandler ErrorHandler)
	// Removes your app’s local notifications that are pending and match the specified identifiers.
	RemovePendingNotificationRequestsWithIdentifiers(identifiers []string)
	// Removes all of your app’s pending local notifications.
	RemoveAllPendingNotificationRequests()

	// Removes your app’s notifications from Notification Center that match the specified identifiers.
	RemoveDeliveredNotificationsWithIdentifiers(identifiers []string)
	// Removes all of your app’s delivered notifications from Notification Center.
	RemoveAllDeliveredNotifications()

	// Registers the notification categories that your app supports.
	SetNotificationCategories(categories foundation.INSSet)

	// The error domain for notifications.
	UNErrorDomain() string
}

An interface definition for the UNUserNotificationCenter class.

Managing the notification center

  • [IUNUserNotificationCenter.GetNotificationSettingsWithCompletionHandler]: Retrieves the authorization and feature-related settings for your app.
  • [IUNUserNotificationCenter.SetBadgeCountWithCompletionHandler]: Updates the badge count for your app’s icon.

Requesting authorization

  • [IUNUserNotificationCenter.RequestAuthorizationWithOptionsCompletionHandler]: Requests a person’s authorization to allow local and remote notifications for your app.

Processing received notifications

  • [IUNUserNotificationCenter.Delegate]: The notification center’s delegate.
  • [IUNUserNotificationCenter.SetDelegate]
  • [IUNUserNotificationCenter.SupportsContentExtensions]: A Boolean value that indicates whether the device supports notification content extensions.

Scheduling notifications

  • [IUNUserNotificationCenter.AddNotificationRequestWithCompletionHandler]: Schedules the delivery of a local notification.
  • [IUNUserNotificationCenter.RemovePendingNotificationRequestsWithIdentifiers]: Removes your app’s local notifications that are pending and match the specified identifiers.
  • [IUNUserNotificationCenter.RemoveAllPendingNotificationRequests]: Removes all of your app’s pending local notifications.

Removing delivered notifications

  • [IUNUserNotificationCenter.RemoveDeliveredNotificationsWithIdentifiers]: Removes your app’s notifications from Notification Center that match the specified identifiers.
  • [IUNUserNotificationCenter.RemoveAllDeliveredNotifications]: Removes all of your app’s delivered notifications from Notification Center.

Managing notification categories

  • [IUNUserNotificationCenter.SetNotificationCategories]: Registers the notification categories that your app supports.

Handling errors

  • [IUNUserNotificationCenter.UNErrorDomain]: The error domain for notifications.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter

type UNAlertStyle

type UNAlertStyle int

See: https://developer.apple.com/documentation/UserNotifications/UNAlertStyle

const (
	// UNAlertStyleAlert: Modal alerts.
	UNAlertStyleAlert UNAlertStyle = 2
	// UNAlertStyleBanner: Banner alerts.
	UNAlertStyleBanner UNAlertStyle = 1
	// UNAlertStyleNone: No alert.
	UNAlertStyleNone UNAlertStyle = 0
)

func (UNAlertStyle) String

func (e UNAlertStyle) String() string

type UNAuthorizationOptions

type UNAuthorizationOptions uint

See: https://developer.apple.com/documentation/UserNotifications/UNAuthorizationOptions

const (
	// UNAuthorizationOptionAlert: The ability to display alerts.
	UNAuthorizationOptionAlert UNAuthorizationOptions = 4
	// UNAuthorizationOptionBadge: The ability to update the app’s badge.
	UNAuthorizationOptionBadge UNAuthorizationOptions = 1
	// UNAuthorizationOptionCarPlay: The ability to display notifications in a CarPlay environment.
	UNAuthorizationOptionCarPlay UNAuthorizationOptions = 8
	// UNAuthorizationOptionCriticalAlert: The ability to play sounds for critical alerts.
	UNAuthorizationOptionCriticalAlert UNAuthorizationOptions = 16
	// UNAuthorizationOptionProvidesAppNotificationSettings: An option indicating the system should display a button for in-app notification settings.
	UNAuthorizationOptionProvidesAppNotificationSettings UNAuthorizationOptions = 32
	// UNAuthorizationOptionProvisional: The ability to post noninterrupting notifications provisionally to the Notification Center.
	UNAuthorizationOptionProvisional UNAuthorizationOptions = 64
	// UNAuthorizationOptionSound: The ability to play sounds.
	UNAuthorizationOptionSound UNAuthorizationOptions = 2
	// Deprecated.
	UNAuthorizationOptionAnnouncement UNAuthorizationOptions = 128
	// Deprecated.
	UNAuthorizationOptionTimeSensitive UNAuthorizationOptions = 256
)
const (

	// UNAuthorizationOptionNone is no authorization options.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNAuthorizationOptionNone
	UNAuthorizationOptionNone UNAuthorizationOptions = 0
)

UNAuthorizationOptions values.

func (UNAuthorizationOptions) String

func (e UNAuthorizationOptions) String() string

type UNAuthorizationStatus

type UNAuthorizationStatus int

See: https://developer.apple.com/documentation/UserNotifications/UNAuthorizationStatus

const (
	// UNAuthorizationStatusAuthorized: The app is authorized to schedule or receive notifications.
	UNAuthorizationStatusAuthorized UNAuthorizationStatus = 2
	// UNAuthorizationStatusDenied: The app isn’t authorized to schedule or receive notifications.
	UNAuthorizationStatusDenied UNAuthorizationStatus = 1
	// UNAuthorizationStatusEphemeral: The app is authorized to schedule or receive notifications for a limited amount of time.
	UNAuthorizationStatusEphemeral UNAuthorizationStatus = 4
	// UNAuthorizationStatusNotDetermined: The user hasn’t yet made a choice about whether the app is allowed to schedule notifications.
	UNAuthorizationStatusNotDetermined UNAuthorizationStatus = 0
	// UNAuthorizationStatusProvisional: The application is provisionally authorized to post noninterruptive user notifications.
	UNAuthorizationStatusProvisional UNAuthorizationStatus = 3
)

func (UNAuthorizationStatus) String

func (e UNAuthorizationStatus) String() string

type UNCalendarNotificationTrigger

type UNCalendarNotificationTrigger struct {
	UNNotificationTrigger
}

A trigger condition that causes a notification the system delivers at a specific date and time.

Overview

Create a UNCalendarNotificationTrigger object when you want to schedule the delivery of a local notification at the date and time you specify. You use an NSDateComponents object to specify only the time values that you want the system to use to determine the matching date and time.

Listing 1 creates a trigger that delivers its notification every morning at 8:30. The repeating behavior is achieved by specifying `true` for the `repeats` parameter when creating the trigger.

Listing 1. Creating a trigger that repeats at a specific time

Getting the Trigger Information

See: https://developer.apple.com/documentation/UserNotifications/UNCalendarNotificationTrigger

func NewUNCalendarNotificationTrigger

func NewUNCalendarNotificationTrigger() UNCalendarNotificationTrigger

NewUNCalendarNotificationTrigger creates a new UNCalendarNotificationTrigger instance.

func NewUNCalendarNotificationTriggerWithDateMatchingComponentsRepeats

func NewUNCalendarNotificationTriggerWithDateMatchingComponentsRepeats(dateComponents foundation.NSDateComponents, repeats bool) UNCalendarNotificationTrigger

Creates a calendar trigger using the date components parameter.

dateComponents: The temporal information to use when constructing the trigger. Provide only the date components that are relevant for your trigger.

repeats: Specify false to deliver the notification one time. Specify true to reschedule the notification request each time the system delivers the notification.

Return Value

A new calendar trigger based on the specified temporal information.

Discussion

If you specify `true` for the `repeats` parameter, you must explicitly remove the notification request to stop the delivery of the associated notification. Use the methods of UNUserNotificationCenter to remove notification requests that are no longer needed.

See: https://developer.apple.com/documentation/UserNotifications/UNCalendarNotificationTrigger/init(dateMatching:repeats:)

func UNCalendarNotificationTriggerFromID

func UNCalendarNotificationTriggerFromID(id objc.ID) UNCalendarNotificationTrigger

UNCalendarNotificationTriggerFromID constructs a UNCalendarNotificationTrigger from an objc.ID.

A trigger condition that causes a notification the system delivers at a specific date and time.

func (UNCalendarNotificationTrigger) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNCalendarNotificationTrigger) DateComponents

The date components to construct this object.

Discussion

Use this property to review the date components associated with this trigger.

See: https://developer.apple.com/documentation/UserNotifications/UNCalendarNotificationTrigger/dateComponents

func (UNCalendarNotificationTrigger) Init

Init initializes the instance.

func (UNCalendarNotificationTrigger) NextTriggerDate

func (u UNCalendarNotificationTrigger) NextTriggerDate() foundation.INSDate

The next date at which the trigger conditions are met.

Return Value

The next trigger date.

Discussion

Use this property to find out when the system will deliver a notification associated with this trigger.

See: https://developer.apple.com/documentation/UserNotifications/UNCalendarNotificationTrigger/nextTriggerDate()

type UNCalendarNotificationTriggerClass

type UNCalendarNotificationTriggerClass struct {
	// contains filtered or unexported fields
}

func GetUNCalendarNotificationTriggerClass

func GetUNCalendarNotificationTriggerClass() UNCalendarNotificationTriggerClass

GetUNCalendarNotificationTriggerClass returns the class object for UNCalendarNotificationTrigger.

func (UNCalendarNotificationTriggerClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNCalendarNotificationTriggerClass) Class

Class returns the underlying Objective-C class pointer.

type UNErrorCode

type UNErrorCode int

See: https://developer.apple.com/documentation/UserNotifications/UNError/Code

const (
	// UNErrorCodeAttachmentCorrupt: The file for an attachment is corrupt.
	UNErrorCodeAttachmentCorrupt UNErrorCode = 105
	// UNErrorCodeAttachmentInvalidFileSize: An attachment is too large.
	UNErrorCodeAttachmentInvalidFileSize UNErrorCode = 102
	// UNErrorCodeAttachmentInvalidURL: The URL for an attachment was invalid.
	UNErrorCodeAttachmentInvalidURL UNErrorCode = 100
	// UNErrorCodeAttachmentMoveIntoDataStoreFailed: An error occurred when trying to move an attachment to the system data store.
	UNErrorCodeAttachmentMoveIntoDataStoreFailed UNErrorCode = 104
	// UNErrorCodeAttachmentNotInDataStore: The specified attachment isn’t in the system data store.
	UNErrorCodeAttachmentNotInDataStore UNErrorCode = 103
	// UNErrorCodeAttachmentUnrecognizedType: The file type of an attachment isn’t supported.
	UNErrorCodeAttachmentUnrecognizedType       UNErrorCode = 101
	UNErrorCodeBadgeInputInvalid                UNErrorCode = 1600
	UNErrorCodeContentProvidingInvalid          UNErrorCode = 1501
	UNErrorCodeContentProvidingObjectNotAllowed UNErrorCode = 1500
	// UNErrorCodeNotificationInvalidNoContent: The notification has no user-facing content, but should.
	UNErrorCodeNotificationInvalidNoContent UNErrorCode = 1401
	// UNErrorCodeNotificationInvalidNoDate: The notification doesn’t have an associated date, but should.
	UNErrorCodeNotificationInvalidNoDate UNErrorCode = 1400
	// UNErrorCodeNotificationsNotAllowed: Notifications aren’t allowed.
	UNErrorCodeNotificationsNotAllowed UNErrorCode = 1
)

func (UNErrorCode) String

func (e UNErrorCode) String() string

type UNMutableNotificationContent

type UNMutableNotificationContent struct {
	UNNotificationContent
}

The editable content for a notification.

Overview

Create a UNMutableNotificationContent object when you want to specify the payload for a local notification. Specifically, use this object to specify the title and message for an alert, the sound to play, or the value to assign to your app’s badge. You might also provide details about how the system handles the notification. For example, you can specify a custom launch image and a thread identifier for visually grouping related notifications.

After creating your content object, assign it to a UNNotificationRequest object, add a trigger condition, and schedule your notification. The trigger condition defines when the system delivers the notification to the user. Listing 1 shows the scheduling of a local notification that displays an alert and plays a sound after a delay of five seconds. Store the strings for the alert’s title and body in the app’s `Localizable.Strings()` file.

Listing 1. Creating the content for a local notification

Localizing the Alert Strings

Localize the strings you display in a notification alert for the current user. Although you can use the NSLocalizedString macros to load strings from your app’s resource files, a better option is to specify your string using the localizedUserNotificationString(forKey:arguments:) method of NSString. The localizedUserNotificationString(forKey:arguments:) method delays the loading of the localized string until the system delivers the notification. If the user changes the language setting before the system delivers a notification, the system updates the alert text to the user’s current language instead of the language in use when the system scheduled the notification.

See: https://developer.apple.com/documentation/UserNotifications/UNMutableNotificationContent

func NewUNMutableNotificationContent

func NewUNMutableNotificationContent() UNMutableNotificationContent

NewUNMutableNotificationContent creates a new UNMutableNotificationContent instance.

func UNMutableNotificationContentFromID

func UNMutableNotificationContentFromID(id objc.ID) UNMutableNotificationContent

UNMutableNotificationContentFromID constructs a UNMutableNotificationContent from an objc.ID.

The editable content for a notification.

func (UNMutableNotificationContent) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNMutableNotificationContent) Init

Init initializes the instance.

type UNMutableNotificationContentClass

type UNMutableNotificationContentClass struct {
	// contains filtered or unexported fields
}

func GetUNMutableNotificationContentClass

func GetUNMutableNotificationContentClass() UNMutableNotificationContentClass

GetUNMutableNotificationContentClass returns the class object for UNMutableNotificationContent.

func (UNMutableNotificationContentClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNMutableNotificationContentClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotification

type UNNotification struct {
	objectivec.Object
}

The data for a local or remote notification the system delivers to your app.

Overview

A UNNotification object contains the initial notification request, which contains the notification’s payload, and the date that the system delivered the notification.

Don’t create notification objects directly. When handling notifications, the system delivers notification objects to your UNUserNotificationCenterDelegate object. The UNUserNotificationCenter object also maintains the list of notifications that the system delivers, and you use the [GetDeliveredNotificationsWithCompletionHandler] method to retrieve those objects.

Getting the Notification Details

See: https://developer.apple.com/documentation/UserNotifications/UNNotification

func NewUNNotification

func NewUNNotification() UNNotification

NewUNNotification creates a new UNNotification instance.

func UNNotificationFromID

func UNNotificationFromID(id objc.ID) UNNotification

UNNotificationFromID constructs a UNNotification from an objc.ID.

The data for a local or remote notification the system delivers to your app.

func (UNNotification) Autorelease

func (u UNNotification) Autorelease() UNNotification

Autorelease adds the receiver to the current autorelease pool.

func (UNNotification) Date

The delivery date of the notification.

Discussion

The system displays this date to the user in Notification Center.

See: https://developer.apple.com/documentation/UserNotifications/UNNotification/date

func (UNNotification) EncodeWithCoder

func (u UNNotification) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotification) Init

func (u UNNotification) Init() UNNotification

Init initializes the instance.

func (UNNotification) Request

The notification request containing the payload and trigger condition for the notification.

Discussion

For local notifications, the request object is a copy of the one you originally configured. For remote notifications, the system synthesizes the request object from information received from Apple Push Notification service.

See: https://developer.apple.com/documentation/UserNotifications/UNNotification/request

type UNNotificationAction

type UNNotificationAction struct {
	objectivec.Object
}

A task your app performs in response to a notification that the system delivers.

Overview

Use UNNotificationAction objects to define the actions that your app can perform in response to a delivered notification. You define the actions that your app supports. For example, a meeting app might define actions for accepting or rejecting a meeting invitation. The action object itself contains the title to display in an action button and the button’s appearance. After creating action objects, add them to a UNNotificationCategory object and register your categories with the system.

For information on how to define actions and categories, see Declaring your actionable notification types.

Responding to the Selection of Actions

When the user selects one of your actions in response to a notification, the system notifies the delegate of the shared UNUserNotificationCenter object. Specifically, the system calls the [UserNotificationCenterDidReceiveNotificationResponseWithCompletionHandler] method of your delegate object. The response object passed to your delegate includes the UNNotificationAction.Identifier string of the action the user selects, which you can use to perform the corresponding task.

For information on how to handle actions, see Handling notifications and notification-related actions.

Getting Information

Getting Options

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction

func NewUNNotificationAction

func NewUNNotificationAction() UNNotificationAction

NewUNNotificationAction creates a new UNNotificationAction instance.

func NewUNNotificationActionWithIdentifierTitleOptions

func NewUNNotificationActionWithIdentifierTitleOptions(identifier string, title string, options UNNotificationActionOptions) UNNotificationAction

Creates an action object by using the specified title and options.

identifier: The string that you use internally to identify the action. This string must be unique among your app’s supported actions. When the user selects the action, the system passes this string to your app and asks the user to perform the related task. This parameter must not be `nil` or an empty string.

title: The localized string the system displays to the user. The system displays this string as the title of a button, which the system adds to the notification interface. This parameter must not be `nil`.

options: Additional options that describe how the action behaves. Include options when you need the related behavior. For a list of possible values, see UNNotificationActionOptions.

Return Value

An action object that the system initializes.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/init(identifier:title:options:)

func NewUNNotificationActionWithIdentifierTitleOptionsIcon

func NewUNNotificationActionWithIdentifierTitleOptionsIcon(identifier string, title string, options UNNotificationActionOptions, icon IUNNotificationActionIcon) UNNotificationAction

Creates an action object by using the specified title, options, and icon.

identifier: The string that you use internally to identify the action. This string must be unique among your app’s supported actions. When the user selects the action, the system passes this string to your app and asks the user to perform the related task. This parameter must not be `nil` or an empty string.

title: The localized string the system displays to the user. The system displays this string as the title of a button, which the system adds to the notification interface. This parameter must not be `nil`.

options: Additional options that describe how the action behaves. Include options when you need the related behavior. For a list of possible values, see UNNotificationActionOptions.

icon: The icon that the system displays to the user.

Return Value

An action object that the system initializes.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/init(identifier:title:options:icon:)

func UNNotificationActionFromID

func UNNotificationActionFromID(id objc.ID) UNNotificationAction

UNNotificationActionFromID constructs a UNNotificationAction from an objc.ID.

A task your app performs in response to a notification that the system delivers.

func (UNNotificationAction) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationAction) EncodeWithCoder

func (u UNNotificationAction) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationAction) Icon

The icon associated with the action.

Discussion

The system displays this icon in the notification interface to help the user identify the app associated with the action.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/icon

func (UNNotificationAction) Identifier

func (u UNNotificationAction) Identifier() string

The unique string that your app uses to identify the action.

Discussion

When the user selects an action, the system reports the value of this string to your app. Because your app handles all actions by using a single delegate method, the identifier strings for all of your app’s actions must be unique.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/identifier

func (UNNotificationAction) Init

Init initializes the instance.

func (UNNotificationAction) Options

The behaviors associated with the action.

Discussion

You app should define options for an action when your app requires the corresponding behavior.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/options

func (UNNotificationAction) Title

func (u UNNotificationAction) Title() string

The localized string to use as the title of the action.

Discussion

The system displays this string as the title of the button that the user taps or selects in the notification interface.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/title

type UNNotificationActionClass

type UNNotificationActionClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationActionClass

func GetUNNotificationActionClass() UNNotificationActionClass

GetUNNotificationActionClass returns the class object for UNNotificationAction.

func (UNNotificationActionClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationActionClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationActionIcon

type UNNotificationActionIcon struct {
	objectivec.Object
}

An icon associated with an action.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationActionIcon

func NewUNNotificationActionIcon

func NewUNNotificationActionIcon() UNNotificationActionIcon

NewUNNotificationActionIcon creates a new UNNotificationActionIcon instance.

func NewUNNotificationActionIconWithSystemImageName

func NewUNNotificationActionIconWithSystemImageName(systemImageName string) UNNotificationActionIcon

Creates an action icon by using a system symbol image.

systemImageName: The name of the system symbol image. Use the SF Symbols app to look up the names of system symbol images. Download this app from the design resources page at developer.apple.com.

Return Value

An action icon that the system initializes with the system symbol image that your app specifies.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationActionIcon/init(systemImageName:)

func NewUNNotificationActionIconWithTemplateImageName

func NewUNNotificationActionIconWithTemplateImageName(templateImageName string) UNNotificationActionIcon

Creates an action icon based on an image in your app’s bundle, preferably in an asset catalog.

templateImageName: The name of a custom image in the app’s asset catalog. If the image isn’t in your app’s asset catalog, this method searches the app bundle for the image.

You don’t need to specify the filename extension or the `@2x` or `@3x` modifiers for this name. This method retrieves the appropriate image based on the system and the available image resources.

Return Value

An action icon initialized with the specified template image provided by your app.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationActionIcon/init(templateImageName:)

func UNNotificationActionIconFromID

func UNNotificationActionIconFromID(id objc.ID) UNNotificationActionIcon

UNNotificationActionIconFromID constructs a UNNotificationActionIcon from an objc.ID.

An icon associated with an action.

func (UNNotificationActionIcon) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationActionIcon) EncodeWithCoder

func (u UNNotificationActionIcon) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationActionIcon) Init

Init initializes the instance.

type UNNotificationActionIconClass

type UNNotificationActionIconClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationActionIconClass

func GetUNNotificationActionIconClass() UNNotificationActionIconClass

GetUNNotificationActionIconClass returns the class object for UNNotificationActionIcon.

func (UNNotificationActionIconClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationActionIconClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationActionOptions

type UNNotificationActionOptions uint

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationActionOptions

const (
	// UNNotificationActionOptionAuthenticationRequired: The action can be performed only on an unlocked device.
	UNNotificationActionOptionAuthenticationRequired UNNotificationActionOptions = 1
	// UNNotificationActionOptionDestructive: The action performs a destructive task.
	UNNotificationActionOptionDestructive UNNotificationActionOptions = 2
	// UNNotificationActionOptionForeground: The action causes the app to launch in the foreground.
	UNNotificationActionOptionForeground UNNotificationActionOptions = 4
)
const (

	// UNNotificationActionOptionNone is the action has the default behavior.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationActionOptionNone
	UNNotificationActionOptionNone UNNotificationActionOptions = 0
)

UNNotificationActionOptions values.

func (UNNotificationActionOptions) String

type UNNotificationArrayHandler added in v0.5.1

type UNNotificationArrayHandler = func(*[]UNNotification)

UNNotificationArrayHandler handles The block to execute with the results.

  • notifications: An array of UNNotification(<doc://com.apple.usernotifications/documentation/UserNotifications/UNNotification>) objects representing the local and remote notifications of your app that have been delivered and are still visible in Notification Center. If none of your app’s notifications are visible in Notification Center, the array is empty.

Used by:

  • [UNUserNotificationCenter.GetDeliveredNotificationsWithCompletionHandler]

type UNNotificationAttachment

type UNNotificationAttachment struct {
	objectivec.Object
}

A media file associated with a notification.

Overview

Create a UNNotificationAttachment object when you want to include audio, image, or video content together in an alert-based notification. When creating the UNNotificationAttachment object, the file you specify must be on disk, and the file format must be one of the supported types.

You’re responsible for supplying attachments before the system displays your notification’s alert. For local notifications, add attachments when creating the notification’s content. For remote notifications, use a notification service app extension to download the attached files and then add them to the notification’s content before delivery.

The system validates attachments before displaying the associated notification. If you attach a file to a local notification request that’s corrupted, invalid, or of an unsupported file type, the system doesn’t schedule your request. For remote notifications, the system validates attachments after your notification service app extension finishes. Once validated, the system moves the attached files into the attachment data store so that the appropriate processes can access the files. The system copies attachments located inside an app’s bundle.

Supported File Types

Table 1 lists the types of files you can include as an attachment and the supported file formats. The table also lists the maximum size allowed for attachments of each type. An image file may contain a static image or an animated image sequence.

Table 1. Supported attachment file types

[Table data omitted]

When creating an attachment, you can specify optional details about how to present the thumbnail image for the image or movie. Use the UNNotificationAttachment.UNNotificationAttachmentOptionsThumbnailClippingRectKey option to use only the specified portion of an image as a thumbnail. For animated images and movies, use the UNNotificationAttachment.UNNotificationAttachmentOptionsThumbnailTimeKey option to select which frame to use for the thumbnail image.

The system limits the amount of storage space allocated for attachments for each app. To delete attachments, use the methods of the UNUserNotificationCenter class to remove the notification requests that contain those attachments.

Creating an Attachment

Getting the Attachment Contents

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachment

func NewUNNotificationAttachment

func NewUNNotificationAttachment() UNNotificationAttachment

NewUNNotificationAttachment creates a new UNNotificationAttachment instance.

func NewUNNotificationAttachmentWithIdentifierURLOptionsError

func NewUNNotificationAttachmentWithIdentifierURLOptionsError(identifier string, URL foundation.INSURL, options foundation.INSDictionary) (UNNotificationAttachment, error)

Creates an attachment object from the specified file and options.

identifier: The unique identifier of the attachment. Use this string to identify the attachment later. If you specify an empty string, this method creates a unique identifier string for you.

URL: The URL of the file you want to attach to the notification. The URL must be a file URL and the file must be readable by the current process. This parameter must not be `nil`. For a list of supported file types, see UNNotificationAttachment.

options: A dictionary of options related to the attached file. Use the options to specify meta information about the attachment, such as the clipping rectangle to use for the resulting thumbnail.

Return Value

An attachment object containing information about the specified file or `nil` if the attachment could not be created.

Discussion

This method verifies that the specified file is readable and that the file format is one of the supported types. When errors occur, the method provides an appropriate `error` object.

When you schedule a notification request containing the attachment, the system moves the attachment’s file to a new location to facilitate access by the appropriate processes. After the move, the only way to access the file is using the methods of the UNUserNotificationCenter object.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachment/init(identifier:url:options:)

func UNNotificationAttachmentFromID

func UNNotificationAttachmentFromID(id objc.ID) UNNotificationAttachment

UNNotificationAttachmentFromID constructs a UNNotificationAttachment from an objc.ID.

A media file associated with a notification.

func (UNNotificationAttachment) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationAttachment) EncodeWithCoder

func (u UNNotificationAttachment) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationAttachment) Identifier

func (u UNNotificationAttachment) Identifier() string

The unique identifier for the attachment.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachment/identifier

func (UNNotificationAttachment) Init

Init initializes the instance.

func (UNNotificationAttachment) Type

The UTI type of the attachment.

Discussion

The system derives the value of this property from the attachment data.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachment/type

func (UNNotificationAttachment) UNNotificationAttachmentOptionsThumbnailClippingRectKey

func (u UNNotificationAttachment) UNNotificationAttachmentOptionsThumbnailClippingRectKey() string

The clipping rectangle for a thumbnail image.

See: https://developer.apple.com/documentation/usernotifications/unnotificationattachmentoptionsthumbnailclippingrectkey

func (UNNotificationAttachment) UNNotificationAttachmentOptionsThumbnailHiddenKey

func (u UNNotificationAttachment) UNNotificationAttachmentOptionsThumbnailHiddenKey() string

A Boolean value indicating whether the system hides the attachment’s thumbnail.

See: https://developer.apple.com/documentation/usernotifications/unnotificationattachmentoptionsthumbnailhiddenkey

func (UNNotificationAttachment) UNNotificationAttachmentOptionsThumbnailTimeKey

func (u UNNotificationAttachment) UNNotificationAttachmentOptionsThumbnailTimeKey() string

The frame number of an animation to use as a thumbnail image.

See: https://developer.apple.com/documentation/usernotifications/unnotificationattachmentoptionsthumbnailtimekey

func (UNNotificationAttachment) UNNotificationAttachmentOptionsTypeHintKey

func (u UNNotificationAttachment) UNNotificationAttachmentOptionsTypeHintKey() string

A hint about an attachment’s file type.

See: https://developer.apple.com/documentation/usernotifications/unnotificationattachmentoptionstypehintkey

func (UNNotificationAttachment) URL

The URL of the file for this attachment.

Discussion

The file at the specified URL is security scoped to your app. Before you access it, call the startAccessingSecurityScopedResource() method of NSURL.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttachment/url

type UNNotificationAttachmentClass

type UNNotificationAttachmentClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationAttachmentClass

func GetUNNotificationAttachmentClass() UNNotificationAttachmentClass

GetUNNotificationAttachmentClass returns the class object for UNNotificationAttachment.

func (UNNotificationAttachmentClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationAttachmentClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationAttributedMessageContext

type UNNotificationAttributedMessageContext struct {
	objectivec.Object
}

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAttributedMessageContext

func NewUNNotificationAttributedMessageContext

func NewUNNotificationAttributedMessageContext() UNNotificationAttributedMessageContext

NewUNNotificationAttributedMessageContext creates a new UNNotificationAttributedMessageContext instance.

func UNNotificationAttributedMessageContextFromID

func UNNotificationAttributedMessageContextFromID(id objc.ID) UNNotificationAttributedMessageContext

UNNotificationAttributedMessageContextFromID constructs a UNNotificationAttributedMessageContext from an objc.ID.

func (UNNotificationAttributedMessageContext) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationAttributedMessageContext) Init

Init initializes the instance.

type UNNotificationAttributedMessageContextClass

type UNNotificationAttributedMessageContextClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationAttributedMessageContextClass

func GetUNNotificationAttributedMessageContextClass() UNNotificationAttributedMessageContextClass

GetUNNotificationAttributedMessageContextClass returns the class object for UNNotificationAttributedMessageContext.

func (UNNotificationAttributedMessageContextClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationAttributedMessageContextClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationCategory

type UNNotificationCategory struct {
	objectivec.Object
}

A type of notification your app supports and the custom actions that the system displays.

Overview

A UNNotificationCategory object defines a type of notification that your executable can receive. You create category objects to define your app’s — notifications that have action buttons the user can select in response to the notification. Each category object you create stores the actions and other behaviors associated with a specific type of notification. Register your category objects using the [SetNotificationCategories] method of UNUserNotificationCenter. You can register as many category objects as you need.

To apply category objects to your notifications, include the category’s identifier string in the payload of any notifications you create. For local notifications, put this string in the UNNotificationCategory.CategoryIdentifier property of the UNMutableNotificationContent object that you use to specify the notification’s content. For remote notifications, use this string as the value of the `category` key in the `aps` dictionary of your payload.

Categories can have associated actions, which define custom buttons the system displays for notifications of that category. When the system has unlimited space, the system displays up to 10 actions. When the system has limited space, the system displays at most two actions.

Getting the Information

Getting the Options

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory

func NewUNNotificationCategory

func NewUNNotificationCategory() UNNotificationCategory

NewUNNotificationCategory creates a new UNNotificationCategory instance.

func NewUNNotificationCategoryWithIdentifierActionsIntentIdentifiersHiddenPreviewsBodyPlaceholderCategorySummaryFormatOptions

func NewUNNotificationCategoryWithIdentifierActionsIntentIdentifiersHiddenPreviewsBodyPlaceholderCategorySummaryFormatOptions(identifier string, actions []UNNotificationAction, intentIdentifiers []string, hiddenPreviewsBodyPlaceholder string, categorySummaryFormat string, options UNNotificationCategoryOptions) UNNotificationCategory

Creates a category object containing the specified actions, options, placeholder text used when previews aren’t shown, and summary format string.

identifier: The unique identifier for the category. Each category that your app uses must have a unique identifier. Don’t specify an empty string.

actions: The actions to display when the system delivers notifications of this type. When minimal space is available, the system displays only the first two actions in the array. You may specify an empty array for this parameter if you don’t want to display custom actions.

intentIdentifiers: The intent identifier strings that you want to associate with notifications of this type. The Intents framework defines constants for each type of intent that you can associate with your notifications.

hiddenPreviewsBodyPlaceholder: A placeholder string to display when the user has disabled notification previews for the app. Include the characters `%u` (the only supported formatting characters) in the string to represent the number of notifications with the same thread identifier. For example, the string “`%u Messages`” becomes “`2 Messages`” when there are two messages.

To specify different strings for the singular and plural cases, use the localizedUserNotificationString(forKey:arguments:) method of NSString to specify the value for this parameter. The key passed to that method contains the identifier of an entry in a `XCUIElementTypeStringsdict` property list of your project. A strings dictionary lets you specify different formatted strings based on the language rules, and is as described in Internationalization and Localization Guide.

categorySummaryFormat: A format string for the summary description used when the system groups the category’s notifications.

options: Additional options for handling notifications of this type. For a list of possible values, see UNNotificationCategoryOptions.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/init(identifier:actions:intentIdentifiers:hiddenPreviewsBodyPlaceholder:categorySummaryFormat:options:)

func NewUNNotificationCategoryWithIdentifierActionsIntentIdentifiersHiddenPreviewsBodyPlaceholderOptions

func NewUNNotificationCategoryWithIdentifierActionsIntentIdentifiersHiddenPreviewsBodyPlaceholderOptions(identifier string, actions []UNNotificationAction, intentIdentifiers []string, hiddenPreviewsBodyPlaceholder string, options UNNotificationCategoryOptions) UNNotificationCategory

Creates a category object containing the specified actions, options, and placeholder text used when previews aren’t shown.

identifier: The unique identifier for the category. Each category that your app uses must have a unique identifier. Don’t specify an empty string.

actions: The actions to display when the system delivers notifications of this type. When minimal space is available, the system displays only the first two actions in the array. You may specify an empty array for this parameter if you don’t want to display custom actions.

intentIdentifiers: The intent identifier strings that you want to associate with notifications of this type. The Intents framework defines constants for each type of intent that you can associate with your notifications.

hiddenPreviewsBodyPlaceholder: A placeholder string to display when the user has disabled notification previews for the app. Include the characters `%u` (the only supported formatting characters) in the string to represent the number of notifications with the same thread identifier. For example, the string “`%u Messages`” becomes “`2 Messages`” when there are two messages.

To specify different strings for the singular and plural cases, use the localizedUserNotificationString(forKey:arguments:) method of NSString to specify the value for this parameter. The key passed to that method contains the identifier of an entry in a `XCUIElementTypeStringsdict` property list of your project. A strings dictionary lets you specify different formatted strings based on the language rules, and is as described in Internationalization and Localization Guide.

options: Additional options for handling notifications of this type. For a list of possible values, see UNNotificationCategoryOptions.

Return Value

An initialized category object.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/init(identifier:actions:intentIdentifiers:hiddenPreviewsBodyPlaceholder:options:)

func NewUNNotificationCategoryWithIdentifierActionsIntentIdentifiersOptions

func NewUNNotificationCategoryWithIdentifierActionsIntentIdentifiersOptions(identifier string, actions []UNNotificationAction, intentIdentifiers []string, options UNNotificationCategoryOptions) UNNotificationCategory

Creates a category object containing the specified actions and options.

identifier: The unique identifier for the category. Each category that your app uses must have a unique identifier. Don’t specify an empty string.

actions: The actions to display when the system delivers notifications of this type. When minimal space is available, the system displays only the first two actions in the array. You may specify an empty array for this parameter if you don’t want to display custom actions.

intentIdentifiers: The intent identifier strings that you want to associate with notifications of this type. The Intents framework defines constants for each type of intent that you can associate with your notifications.

options: Additional options for handling notifications of this type. For a list of possible values, see UNNotificationCategoryOptions.

Return Value

An initialized category object.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/init(identifier:actions:intentIdentifiers:options:)

func UNNotificationCategoryFromID

func UNNotificationCategoryFromID(id objc.ID) UNNotificationCategory

UNNotificationCategoryFromID constructs a UNNotificationCategory from an objc.ID.

A type of notification your app supports and the custom actions that the system displays.

func (UNNotificationCategory) Actions

The actions to display when the system delivers notifications of this type.

Discussion

When displaying a notification assigned to this category, the system adds a button to the notification interface for each action in this property. The system displays these buttons after the notification’s content but before the Dismiss button.

When displaying banner notifications, the system displays only the first two actions.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/actions

func (UNNotificationCategory) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationCategory) CategoryIdentifier

func (u UNNotificationCategory) CategoryIdentifier() string

The identifier of the notification’s category.

See: https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/categoryidentifier

func (UNNotificationCategory) CategorySummaryFormat

func (u UNNotificationCategory) CategorySummaryFormat() string

A format string for the summary description used when the system groups the category’s notifications.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/categorySummaryFormat

func (UNNotificationCategory) EncodeWithCoder

func (u UNNotificationCategory) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationCategory) HiddenPreviewsBodyPlaceholder

func (u UNNotificationCategory) HiddenPreviewsBodyPlaceholder() string

The placeholder text to display when the system disables notification previews for the app.

Discussion

The string in this property may contain the special characters `%u` as a placeholder for the number of messages with the same thread identifier. If your app declares this string in a `XCUIElementTypeStringsdict` property list, the system formats the preview message using the information in that file. For more information about specifying a `XCUIElementTypeStringsdict` property file, see Internationalization and Localization Guide.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/hiddenPreviewsBodyPlaceholder

func (UNNotificationCategory) Identifier

func (u UNNotificationCategory) Identifier() string

The unique string assigned to the category.

Discussion

Use this string to differentiate the different types of notifications that your app can send. To assign a category to a local notification, assign this string to the [CategoryIdentifier] property of the content object. To assign a category to a remote notification, use the string as the value of the `category` key in the notification payload `aps` dictionary.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/identifier

func (UNNotificationCategory) Init

Init initializes the instance.

func (UNNotificationCategory) IntentIdentifiers

func (u UNNotificationCategory) IntentIdentifiers() []string

The intents related to notifications of this category.

Discussion

When the system delivers a notification, the presence of an intent identifier lets the system know that the notification is potentially related to the handling of a request made through Siri.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/intentIdentifiers

func (UNNotificationCategory) Options

Options for how to handle notifications of this type.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory/options

func (UNNotificationCategory) SetCategoryIdentifier

func (u UNNotificationCategory) SetCategoryIdentifier(value string)

func (UNNotificationCategory) SetDestructive

func (u UNNotificationCategory) SetDestructive(value UNNotificationActionOptions)

type UNNotificationCategoryClass

type UNNotificationCategoryClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationCategoryClass

func GetUNNotificationCategoryClass() UNNotificationCategoryClass

GetUNNotificationCategoryClass returns the class object for UNNotificationCategory.

func (UNNotificationCategoryClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationCategoryClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationCategoryOptions

type UNNotificationCategoryOptions uint

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategoryOptions

const (
	// UNNotificationCategoryOptionAllowInCarPlay: Allow CarPlay to display notifications of this type.
	UNNotificationCategoryOptionAllowInCarPlay UNNotificationCategoryOptions = 2
	// UNNotificationCategoryOptionCustomDismissAction: Send dismiss actions to the [UNUserNotificationCenter] object’s delegate for handling.
	UNNotificationCategoryOptionCustomDismissAction UNNotificationCategoryOptions = 1
	// UNNotificationCategoryOptionHiddenPreviewsShowSubtitle: Show the notification’s subtitle, even if the user has disabled notification previews for the app.
	UNNotificationCategoryOptionHiddenPreviewsShowSubtitle UNNotificationCategoryOptions = 8
	// UNNotificationCategoryOptionHiddenPreviewsShowTitle: Show the notification’s title, even if the user has disabled notification previews for the app.
	UNNotificationCategoryOptionHiddenPreviewsShowTitle UNNotificationCategoryOptions = 4
	// Deprecated.
	UNNotificationCategoryOptionAllowAnnouncement UNNotificationCategoryOptions = 16
)
const (

	// UNNotificationCategoryOptionNone is no options.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategoryOptionNone
	UNNotificationCategoryOptionNone UNNotificationCategoryOptions = 0
)

UNNotificationCategoryOptions values.

func (UNNotificationCategoryOptions) String

type UNNotificationCategorySetHandler added in v0.5.1

type UNNotificationCategorySetHandler = func(*foundation.INSSet)

UNNotificationCategorySetHandler handles The block to execute asynchronously with the results.

  • categories: The set of UNNotificationCategory(<doc://com.apple.usernotifications/documentation/UserNotifications/UNNotificationCategory>) objects containing your registered notification types. If your app has not yet registered any categories, this parameter is an empty set.

Used by:

  • [UNUserNotificationCenter.GetNotificationCategoriesWithCompletionHandler]

type UNNotificationClass

type UNNotificationClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationClass

func GetUNNotificationClass() UNNotificationClass

GetUNNotificationClass returns the class object for UNNotification.

func (UNNotificationClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationClass) Class

func (uc UNNotificationClass) Class() objc.Class

Class returns the underlying Objective-C class pointer.

type UNNotificationContent

type UNNotificationContent struct {
	objectivec.Object
}

The uneditable content of a notification.

Overview

A UNNotificationContent object contains the data associated with a notification. When your app receives a notification, the associated UNNotificationRequest object contains an object of this type with the content that your app received. Use the content object to get the details of the notification, including the type of notification that the system delivered, any custom data you stored in the UNNotificationContent.UserInfo dictionary before scheduling the notification, and any attachments.

Don’t create instances of this class directly. For remote notifications, the system derives the contents of this object from the JSON payload that your server sends to the APNS server. For local notifications, create a UNMutableNotificationContent object, and configure the contents of that object instead.

Accessing the primary content

Accessing supplementary content

Reading app configuration

Reading system configuration

Retrieving group information

Updating the notification’s content

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent

func NewUNNotificationContent

func NewUNNotificationContent() UNNotificationContent

NewUNNotificationContent creates a new UNNotificationContent instance.

func UNNotificationContentFromID

func UNNotificationContentFromID(id objc.ID) UNNotificationContent

UNNotificationContentFromID constructs a UNNotificationContent from an objc.ID.

The uneditable content of a notification.

func (UNNotificationContent) Attachments

The visual and audio attachments to display alongside the notification’s main content.

Discussion

Use this property to retrieve the images, movies, and audio files associated with your notification’s content. A notification content app extension might use these values to add the associated content to its view controller.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/attachments

func (UNNotificationContent) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationContent) Badge

The number that your app’s icon displays.

Discussion

When the number in this property is `0`, the system doesn’t display a badge. When the number is greater than `0`, the system displays the badge with the specified number. When the value in this property is `nil`, the system leaves the current badge unchanged.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/badge

func (UNNotificationContent) Body

func (u UNNotificationContent) Body() string

The localized text that provides the notification’s main content.

Discussion

The body text contains the final text that you want to display. If your app isn’t authorized to display alert-based notifications, the system ignores this property.

If you specified two percent symbols (`%%`) in the message body, the system replaces it with a single percent symbol (`%`). The system strips all other printf style escape characters from your string prior to display.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/body

func (UNNotificationContent) CategoryIdentifier

func (u UNNotificationContent) CategoryIdentifier() string

The identifier of the notification’s category.

Discussion

Use notification types to distinguish between the different types of notifications your app supports. You use this support primarily to create actionable notifications with custom action buttons, and to redirect your notifications through either your notification service app extension or your notification content app extension.

For remote notifications, the system sets this property to the value of the `category` key in the `aps` dictionary.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/categoryIdentifier

func (UNNotificationContent) ContentByUpdatingWithProviderError

func (u UNNotificationContent) ContentByUpdatingWithProviderError(provider UNNotificationContentProviding) (IUNNotificationContent, error)

Returns a copy of the notification that includes content from the specified provider.

provider: The notification content providing object.

Return Value

The notification content object for the content handler.

Discussion

The system contextualizes your UNNotificationContent object with other Apple SDK objects conforming to UNNotificationContentProviding. The system specializes the notification and decorates its look and behavior accordingly.

For example, the system treats the notification as a message with an avatar and promotes it to the top of notification center if the object passed in is a valid INSendMessageIntent that conforms to UNNotificationContentProviding. The system throws an error with a UNError.Code, if the UNNotificationContentProviding object is invalid. Pass the valid UNNotificationContent result directly to UNUserNotificationCenter without mutating.

Add this call to the UNNotificationServiceExtension in [DidReceiveNotificationRequestWithContentHandler]. Your app passes the returned UNNotificationContent to the `contentHandler` for incoming push notifications.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/updating(from:)

func (UNNotificationContent) EncodeWithCoder

func (u UNNotificationContent) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationContent) FilterCriteria

func (u UNNotificationContent) FilterCriteria() string

The criteria the system evaluates to determine if it displays the notification in the current Focus.

Discussion

For more information, see SetFocusFilterIntent.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/filterCriteria

func (UNNotificationContent) Init

Init initializes the instance.

func (UNNotificationContent) InterruptionLevel

The notification’s importance and required delivery timing.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/interruptionLevel

func (UNNotificationContent) RelevanceScore

func (u UNNotificationContent) RelevanceScore() float64

The score the system uses to determine if the notification is the summary’s featured notification.

Discussion

The system uses the `relevanceScore`, a value between `0` and `1`, to sort the notifications from your app. The highest score gets featured in the notification summary.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/relevanceScore

func (UNNotificationContent) Sound

The sound that plays when the system delivers the notification.

Discussion

Notifications can play a default sound or a custom sound. For information on how to specify custom sounds for your notifications, see UNNotificationSound.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/sound

func (UNNotificationContent) Subtitle

func (u UNNotificationContent) Subtitle() string

The localized text that provides the notification’s secondary description.

Discussion

Subtitles offer additional context in cases where the title alone isn’t clear. Subtitles aren’t displayed in all cases. If your app isn’t authorized to display alert-based notifications, the system ignores this property.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/subtitle

func (UNNotificationContent) SummaryArgument

func (u UNNotificationContent) SummaryArgument() string

The text the system adds to the notification summary to provide additional context.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/summaryArgument

func (UNNotificationContent) SummaryArgumentCount

func (u UNNotificationContent) SummaryArgumentCount() uint

The number the system adds to the notification summary when the notification represents multiple items.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/summaryArgumentCount

func (UNNotificationContent) TargetContentIdentifier

func (u UNNotificationContent) TargetContentIdentifier() string

The value your app uses to determine which scene to display to handle the notification.

Discussion

Use this value to determine the content to show in your app when the user taps the notification.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/targetContentIdentifier

func (UNNotificationContent) ThreadIdentifier

func (u UNNotificationContent) ThreadIdentifier() string

The identifier that groups related notifications.

Discussion

For remote notifications, the system sets this property to the value of the `thread-id` key in the `aps` dictionary.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/threadIdentifier

func (UNNotificationContent) Title

func (u UNNotificationContent) Title() string

The localized text that provides the notification’s primary description.

Discussion

When a title is present, the system attempts to display a notification alert. If your app isn’t authorized to display alert-based notifications, the system ignores this property.

Title strings should be short, usually only a couple of words describing the reason for the notification. In watchOS, the system displays the title string as part of the short look notification interface, which has limited space.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/title

func (UNNotificationContent) UserInfo

The custom data to associate with the notification.

Discussion

For remote notifications, this property contains the entire notification payload. For local notifications, you configure the property directly before scheduling the notification.

The keys in this dictionary must be property-list types—that’s, they must be types that can be serialized into the property-list format. For information about property-list types, see Property List Programming Guide.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContent/userInfo

type UNNotificationContentClass

type UNNotificationContentClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationContentClass

func GetUNNotificationContentClass() UNNotificationContentClass

GetUNNotificationContentClass returns the class object for UNNotificationContent.

func (UNNotificationContentClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationContentClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationContentHandler

type UNNotificationContentHandler = func(*UNNotificationContent)

UNNotificationContentHandler handles The block to execute with the modified content.

  • contentToDeliver: A UNNotificationContent(<doc://com.apple.usernotifications/documentation/UserNotifications/UNNotificationContent>) object with the content the system displays to the user.

Used by:

type UNNotificationContentProviding

type UNNotificationContentProviding interface {
	objectivec.IObject
}

A protocol the system uses to provide context relevant to user notifications.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationContentProviding

type UNNotificationContentProvidingObject

type UNNotificationContentProvidingObject struct {
	objectivec.Object
}

UNNotificationContentProvidingObject wraps an existing Objective-C object that conforms to the UNNotificationContentProviding protocol.

func UNNotificationContentProvidingObjectFromID

func UNNotificationContentProvidingObjectFromID(id objc.ID) UNNotificationContentProvidingObject

UNNotificationContentProvidingObjectFromID constructs a UNNotificationContentProvidingObject from an objc.ID. The object is determined to conform to the protocol at runtime.

func (UNNotificationContentProvidingObject) BaseObject

type UNNotificationInterruptionLevel

type UNNotificationInterruptionLevel uint

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationInterruptionLevel

const (
	// UNNotificationInterruptionLevelActive: The system presents the notification immediately, lights up the screen, and can play a sound.
	UNNotificationInterruptionLevelActive UNNotificationInterruptionLevel = 1
	// UNNotificationInterruptionLevelCritical: The system presents the notification immediately, lights up the screen, and bypasses the mute switch to play a sound.
	UNNotificationInterruptionLevelCritical UNNotificationInterruptionLevel = 3
	// UNNotificationInterruptionLevelPassive: The system adds the notification to the notification list without lighting up the screen or playing a sound.
	UNNotificationInterruptionLevelPassive UNNotificationInterruptionLevel = 0
	// UNNotificationInterruptionLevelTimeSensitive: The system presents the notification immediately, lights up the screen, can play a sound, and breaks through system notification controls.
	UNNotificationInterruptionLevelTimeSensitive UNNotificationInterruptionLevel = 2
)

func (UNNotificationInterruptionLevel) String

type UNNotificationPresentationOptions

type UNNotificationPresentationOptions uint

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationPresentationOptions

const (
	// UNNotificationPresentationOptionBadge: Apply the notification’s badge value to the app’s icon.
	UNNotificationPresentationOptionBadge UNNotificationPresentationOptions = 1
	// UNNotificationPresentationOptionBanner: Present the notification as a banner.
	UNNotificationPresentationOptionBanner UNNotificationPresentationOptions = 16
	// UNNotificationPresentationOptionList: Show the notification in Notification Center.
	UNNotificationPresentationOptionList UNNotificationPresentationOptions = 8
	// UNNotificationPresentationOptionSound: Play the sound associated with the notification.
	UNNotificationPresentationOptionSound UNNotificationPresentationOptions = 2
	// Deprecated.
	UNNotificationPresentationOptionAlert UNNotificationPresentationOptions = 4
)
const (

	// UNNotificationPresentationOptionNone is no alert.
	//
	// See: https://developer.apple.com/documentation/UserNotifications/UNNotificationPresentationOptionNone
	UNNotificationPresentationOptionNone UNNotificationPresentationOptions = 0
)

UNNotificationPresentationOptions values.

func (UNNotificationPresentationOptions) String

type UNNotificationPresentationOptionsHandler

type UNNotificationPresentationOptionsHandler = func(UNNotificationPresentationOptions)

UNNotificationPresentationOptionsHandler handles The block to execute with the presentation option for the notification.

  • options: The option for notifying the user. Specify UNNotificationPresentationOptionNone(<doc://com.apple.usernotifications/documentation/UserNotifications/UNNotificationPresentationOptionNone>) to silence the notification completely. Specify other values to interact with the user. For a list of possible options, see UNNotificationPresentationOptions(<doc://com.apple.usernotifications/documentation/UserNotifications/UNNotificationPresentationOptions>).

Used by:

  • [UNUserNotificationCenterDelegate.UserNotificationCenterWillPresentNotificationWithCompletionHandler]

type UNNotificationRequest

type UNNotificationRequest struct {
	objectivec.Object
}

A request to schedule a local notification, which includes the content of the notification and the trigger conditions for delivery.

Overview

Create a UNNotificationRequest object when you want to schedule the delivery of a local notification. A notification request object contains a UNNotificationContent object with the payload and the UNNotificationTrigger object with the conditions that trigger the delivery of the notification. To schedule the delivery of your notification, pass your request object to the [AddNotificationRequestWithCompletionHandler] method of the shared user notification center object.

After scheduling a request, you interact with UNNotificationRequest objects in the following ways:

- View your app’s pending notifications by calling the [GetPendingNotificationRequestsWithCompletionHandler] method of your shared user notification center object. - When the system delivers a notification to your app, the provided UNNotification object contains a UNNotificationRequest object that you can inspect to get the notification details. - Use the request’s UNNotificationRequest.Identifier to remove delivered notifications from Notification Center.

When receiving a local or remote notification, use the provided UNNotificationRequest object to fetch details about the notification.

Getting the Request Details

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationRequest

func NewUNNotificationRequest

func NewUNNotificationRequest() UNNotificationRequest

NewUNNotificationRequest creates a new UNNotificationRequest instance.

func NewUNNotificationRequestWithIdentifierContentTrigger

func NewUNNotificationRequestWithIdentifierContentTrigger(identifier string, content IUNNotificationContent, trigger IUNNotificationTrigger) UNNotificationRequest

Creates a notification request object that you use to schedule a notification.

identifier: An identifier for the request; this parameter must not be `nil`. You can use this identifier to cancel the request if it’s still pending (see the [RemovePendingNotificationRequestsWithIdentifiers] method).

content: The content of the notification. This parameter must not be `nil`.

trigger: The condition that causes the system to deliver the notification. Specify `nil` to deliver the notification right away.

Return Value

A new notification request object.

Discussion

Use this method when you want to schedule the delivery of a local notification. This method creates the request object that you subsequently pass to the [AddNotificationRequestWithCompletionHandler] method.

The system uses the `identifier` parameter to determine how to handle the request:

- the system creates a new notification. - the system alerts the user again, replaces the old notification with the new one, and places the new notification at the top of the list. - the new request replaces the pending request.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationRequest/init(identifier:content:trigger:)

func UNNotificationRequestFromID

func UNNotificationRequestFromID(id objc.ID) UNNotificationRequest

UNNotificationRequestFromID constructs a UNNotificationRequest from an objc.ID.

A request to schedule a local notification, which includes the content of the notification and the trigger conditions for delivery.

func (UNNotificationRequest) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationRequest) Content

The content associated with the notification.

Discussion

Use this property to access the contents of the notification.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationRequest/content

func (UNNotificationRequest) EncodeWithCoder

func (u UNNotificationRequest) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationRequest) Identifier

func (u UNNotificationRequest) Identifier() string

The unique identifier for this notification request.

Discussion

Use this string to identify notifications in your app. For example, you can pass this string to the [RemovePendingNotificationRequestsWithIdentifiers] method to cancel a previously scheduled notification.

If you use the same identifier when scheduling a new notification, the system removes the previously scheduled notification with that identifier and replaces it with the new one.

For local notifications, the system sets this property to the value passed to the request’s initializer (see the [RequestWithIdentifierContentTrigger] method). For remote notifications, the system sets this property to the value of the `apns-collapse-id` key that you specified in the APNs request header when generating the remote notification. If your app doesn’t set a value, the system automatically assigns an identifier.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationRequest/identifier

func (UNNotificationRequest) Init

Init initializes the instance.

func (UNNotificationRequest) Trigger

The conditions that trigger the delivery of the notification.

Discussion

For notifications that the system has delivered, use this property to determine what caused the delivery to occur. For remote notifications, this property contains a UNPushNotificationTrigger object. For other notifications, the system sets this type using the trigger condition specified in the original request.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationRequest/trigger

type UNNotificationRequestArrayHandler added in v0.5.1

type UNNotificationRequestArrayHandler = func(*[]UNNotificationRequest)

UNNotificationRequestArrayHandler handles A block for processing notification requests.

  • requests: An array of UNNotificationRequest(<doc://com.apple.usernotifications/documentation/UserNotifications/UNNotificationRequest>) objects representing the scheduled notification requests. If there are no scheduled requests, this array is empty.

Used by:

  • [UNUserNotificationCenter.GetPendingNotificationRequestsWithCompletionHandler]

type UNNotificationRequestClass

type UNNotificationRequestClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationRequestClass

func GetUNNotificationRequestClass() UNNotificationRequestClass

GetUNNotificationRequestClass returns the class object for UNNotificationRequest.

func (UNNotificationRequestClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationRequestClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationResponse

type UNNotificationResponse struct {
	objectivec.Object
}

The user’s response to an actionable notification.

Overview

When the user interacts with a delivered notification, the system delivers a UNNotificationResponse object to your app so that you can process the response. Users can interact with delivered notifications in many ways. If the notification’s category had associated action buttons, they can select one of those buttons. Users can also dismiss the notification without selecting one of your actions and they can open your app. A response object tells you which option the user selected.

You don’t create UNNotificationResponse objects yourself. Instead, the shared user notification center object creates them and delivers them to the [UserNotificationCenterDidReceiveNotificationResponseWithCompletionHandler] method of its delegate object. Use that method to extract any needed information from the response object and take appropriate action.

For more information about responding to actions, see Handling notifications and notification-related actions.

Getting the Response Information

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationResponse

func NewUNNotificationResponse

func NewUNNotificationResponse() UNNotificationResponse

NewUNNotificationResponse creates a new UNNotificationResponse instance.

func UNNotificationResponseFromID

func UNNotificationResponseFromID(id objc.ID) UNNotificationResponse

UNNotificationResponseFromID constructs a UNNotificationResponse from an objc.ID.

The user’s response to an actionable notification.

func (UNNotificationResponse) ActionIdentifier

func (u UNNotificationResponse) ActionIdentifier() string

The identifier string of the action that the user selected.

Discussion

This parameter may contain one the identifier of one of your UNNotificationAction objects or it may contain a system-defined identifier. The system defined identifiers are UNNotificationDefaultActionIdentifier and UNNotificationDismissActionIdentifier, which indicate that the user opened the app or dismissed the notification without any further actions.

For more information about defining custom actions, see Declaring your actionable notification types.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationResponse/actionIdentifier

func (UNNotificationResponse) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationResponse) EncodeWithCoder

func (u UNNotificationResponse) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationResponse) Init

Init initializes the instance.

func (UNNotificationResponse) Notification

func (u UNNotificationResponse) Notification() IUNNotification

The notification to which the user responded.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationResponse/notification

func (UNNotificationResponse) UNNotificationDefaultActionIdentifier

func (u UNNotificationResponse) UNNotificationDefaultActionIdentifier() string

An action that indicates the user opened the app from the notification interface.

See: https://developer.apple.com/documentation/usernotifications/unnotificationdefaultactionidentifier

func (UNNotificationResponse) UNNotificationDismissActionIdentifier

func (u UNNotificationResponse) UNNotificationDismissActionIdentifier() string

The action that indicates the user explicitly dismissed the notification interface.

See: https://developer.apple.com/documentation/usernotifications/unnotificationdismissactionidentifier

type UNNotificationResponseClass

type UNNotificationResponseClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationResponseClass

func GetUNNotificationResponseClass() UNNotificationResponseClass

GetUNNotificationResponseClass returns the class object for UNNotificationResponse.

func (UNNotificationResponseClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationResponseClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationServiceExtension

type UNNotificationServiceExtension struct {
	objectivec.Object
}

An object that modifies the content of a remote notification before it’s delivered to the user.

Overview

A UNNotificationServiceExtension object provides the entry point for a notification service app extension. This object lets you customize the content of a remote notification before the system delivers it to the user. A notification service app extension doesn’t present any UI of its own. Instead, it’s launched on demand when the system delivers a notification of the appropriate type to the user’s device. You use this extension to modify the notification’s content or download content related to the extension. For example, you could use the extension to decrypt an encrypted data block or to download images associated with the notification.

You don’t create UNNotificationServiceExtension objects yourself. Instead, the Xcode template for a notification service extension target contains a subclass for you to modify. Use the methods of that subclass to implement your app extension’s behavior. When your app receives a remote notification for your app, the system loads your extension and calls its UNNotificationServiceExtension.DidReceiveNotificationRequestWithContentHandler method given the following conditions:

- Your app has configured the remote notification to display an alert. - The remote notification’s `aps` dictionary includes the `mutable-content` key with the value set to `1`.

The UNNotificationServiceExtension.DidReceiveNotificationRequestWithContentHandler method performs the main work of your extension. You use that method to make any changes to the notification’s content. That method has a limited amount of time to perform its task and execute the provided completion block. If your method doesn’t finish in time, the system calls the UNNotificationServiceExtension.ServiceExtensionTimeWillExpire method to give you one last chance to submit your changes. If you don’t update the notification content before time expires, the system displays the original content.

As for any app extension, you deliver a notification service app extension class as a bundle inside your app. The template that Xcode provides configures the `Info.Plist()` file automatically for this app extension type. Specifically, it sets the value of the NSExtensionPointIdentifier key to `com.AppleXCUIElementTypeUsernotificationsXCUIElementTypeService()` and sets the value of the NSExtensionPrincipalClass key to the name of your UNNotificationServiceExtension subclass.

For information about how to set up and send remote notifications, see Setting up a remote notification server.

Subclassing Notes

The Xcode templates provide a subclass of UNNotificationServiceExtension for you to modify. You must implement the UNNotificationServiceExtension.DidReceiveNotificationRequestWithContentHandler method and use it to process incoming notifications. It’s also strongly recommended that you override the UNNotificationServiceExtension.ServiceExtensionTimeWillExpire method.

Processing Notifications

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationServiceExtension

func NewUNNotificationServiceExtension

func NewUNNotificationServiceExtension() UNNotificationServiceExtension

NewUNNotificationServiceExtension creates a new UNNotificationServiceExtension instance.

func UNNotificationServiceExtensionFromID

func UNNotificationServiceExtensionFromID(id objc.ID) UNNotificationServiceExtension

UNNotificationServiceExtensionFromID constructs a UNNotificationServiceExtension from an objc.ID.

An object that modifies the content of a remote notification before it’s delivered to the user.

func (UNNotificationServiceExtension) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationServiceExtension) DidReceiveNotificationRequestWithContentHandler

func (u UNNotificationServiceExtension) DidReceiveNotificationRequestWithContentHandler(request IUNNotificationRequest, contentHandler UNNotificationContentHandler)

Asks you to make any needed changes to the notification and notify the system when you’re done.

request: The original notification request. Use this object to get the original content of the notification.

contentHandler: The block to execute with the modified content. This block has no return value and takes the following parameter:

contentToDeliver: A UNNotificationContent object with the content the system displays to the user.

Discussion

Override this method and use it to modify the UNNotificationContent object that the system delivers with the notification. At some point during your implementation, execute the `contentHandler` block and pass it your modified content. If you decide not to modify the content, call the `contentHandler` block with the original content from the `request` parameter.

You can modify any of the content from the original request. You might customize the content for the current user or replace it altogether. You can use this method to download images or movies and add them as attachments to the content. You may also modify the alert text as long as you don’t remove it. If the content object doesn’t contain any alert text, the system ignores your modifications and delivers the original notification content.

Your extension has a limited amount of time (no more than 30 seconds) to modify the content and execute the `contentHandler` block. If you don’t execute that block in a timely manner, the system calls your extension’s [ServiceExtensionTimeWillExpire] method to give you one last chance to execute the block. If you don’t, the system presents the notification’s original content to the user.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationServiceExtension/didReceive(_:withContentHandler:)

func (UNNotificationServiceExtension) DidReceiveNotificationRequestWithContentHandlerSync

func (u UNNotificationServiceExtension) DidReceiveNotificationRequestWithContentHandlerSync(ctx context.Context, request IUNNotificationRequest) (*UNNotificationContent, error)

DidReceiveNotificationRequestWithContentHandlerSync is a synchronous wrapper around UNNotificationServiceExtension.DidReceiveNotificationRequestWithContentHandler. It blocks until the completion handler fires or the context is cancelled.

func (UNNotificationServiceExtension) Init

Init initializes the instance.

func (UNNotificationServiceExtension) ServiceExtensionTimeWillExpire

func (u UNNotificationServiceExtension) ServiceExtensionTimeWillExpire()

Tells you that the system is terminating your extension.

Discussion

If your [DidReceiveNotificationRequestWithContentHandler] method takes too long to execute its completion block, the system calls this method on a separate thread to give you one last chance to execute the block. Use this method to execute the block as quickly as possible. Doing so might mean providing some fallback content. For example, if your extension is still downloading an image file with the intent of attaching it to the notification’s content, update the notification’s alert text to indicate that an image download is in progress. If you fail to execute the completion block from the [DidReceiveNotificationRequestWithContentHandler] method in time, the system displays the notification’s original content.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationServiceExtension/serviceExtensionTimeWillExpire()

type UNNotificationServiceExtensionClass

type UNNotificationServiceExtensionClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationServiceExtensionClass

func GetUNNotificationServiceExtensionClass() UNNotificationServiceExtensionClass

GetUNNotificationServiceExtensionClass returns the class object for UNNotificationServiceExtension.

func (UNNotificationServiceExtensionClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationServiceExtensionClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationSetting

type UNNotificationSetting int

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSetting

const (
	// UNNotificationSettingDisabled: The setting is disabled.
	UNNotificationSettingDisabled UNNotificationSetting = 1
	// UNNotificationSettingEnabled: The setting is enabled.
	UNNotificationSettingEnabled UNNotificationSetting = 2
	// UNNotificationSettingNotSupported: The setting is not available to your app.
	UNNotificationSettingNotSupported UNNotificationSetting = 0
)

func (UNNotificationSetting) String

func (e UNNotificationSetting) String() string

type UNNotificationSettings

type UNNotificationSettings struct {
	objectivec.Object
}

The object for managing notification-related settings and the authorization status of your app.

Overview

A UNNotificationSettings object contains the current authorization status and notification-related settings for your app. Apps must receive authorization to schedule notifications and to interact with the user. Apps that run in CarPlay must similarly receive authorization to do so. Use this object to determine what notification-related actions your app can perform. You might then use that information to enable, disable, or adjust your app’s notification-related behaviors. Regardless of whether you take action, the system enforces your app’s settings by preventing denied interactions from occurring.

You don’t create instances of this class directly. Instead, call the [GetNotificationSettingsWithCompletionHandler] method of your app’s UNUserNotificationCenter object to get the current settings.

For more information about requesting authorization for user interactions, see UNUserNotificationCenter.

Getting the Authorization Status

Getting Device-Specific Settings

Getting Interface Settings

Instance Properties

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings

func NewUNNotificationSettings

func NewUNNotificationSettings() UNNotificationSettings

NewUNNotificationSettings creates a new UNNotificationSettings instance.

func UNNotificationSettingsFromID

func UNNotificationSettingsFromID(id objc.ID) UNNotificationSettings

UNNotificationSettingsFromID constructs a UNNotificationSettings from an objc.ID.

The object for managing notification-related settings and the authorization status of your app.

func (UNNotificationSettings) AlertSetting

The authorization status for displaying alerts.

Discussion

When the value of this property is UNNotificationSettingEnabled, the app is authorized to display alerts. Authorization does not guarantee that alerts always appear on the user’s screen. When a device is unlocked, the [AlertStyle] property determines the presentation style for the alert, which can include not displaying the alert at all.

The system tries to display an alert when the [Title], [Subtitle], or [Body] properties of a UNNotificationContent object contain values, or when the `aps` dictionary in a remote notification contains the `alert` key.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/alertSetting

func (UNNotificationSettings) AlertStyle

func (u UNNotificationSettings) AlertStyle() UNAlertStyle

The type of alert that the app may display when the device is unlocked.

Discussion

When alerts are authorized, this property specifies the presentation style for alerts when the device is unlocked. The user may choose to display alerts as automatically disappearing banners or as modal windows that require explicit dismissal. The user may also choose not to display alerts at all.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/alertStyle

func (UNNotificationSettings) AuthorizationStatus

func (u UNNotificationSettings) AuthorizationStatus() UNAuthorizationStatus

The app’s ability to schedule and receive local and remote notifications.

Discussion

When the value of this property is UNAuthorizationStatusAuthorized, your app is allowed to schedule and receive local and remote notifications. When authorized, use the [AlertSetting], [BadgeSetting], and [SoundSetting] properties to specify which types of interactions are allowed. When the value of the property is UNAuthorizationStatusDenied, the system doesn’t deliver notifications to your app, and the system ignores any attempts to schedule local notifications.

The value of this property is UNAuthorizationStatusNotDetermined if your app has never requested authorization using the [RequestAuthorizationWithOptionsCompletionHandler] method.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/authorizationStatus

func (UNNotificationSettings) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationSettings) BadgeSetting

The setting that indicates whether badges appear on your app’s icon.

Discussion

When the value of this property is UNNotificationSettingEnabled, the app is authorized to badge its icon. The system tries to badge your app’s icon when the [Badge] property of a UNNotificationContent object contain a value, or when the `aps` dictionary in a remote notification contains the `badge` key.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/badgeSetting

func (UNNotificationSettings) CriticalAlertSetting

func (u UNNotificationSettings) CriticalAlertSetting() UNNotificationSetting

The authorization status for playing sounds for critical alerts.

Discussion

When UNNotificationSettingEnabled, this property authorizes the app to play critical sounds that ignore Do Not Disturb and the device’s mute switch.

For local notifications, the system attempts to play a critical sound when the [Sound] property of the UNNotificationContent object contains an object returned by the [DefaultCriticalSound] property, the [CriticalSoundNamed] method, or a related method.

For remote notifications, the system attempts to play a critical sound when the notification’s payload contains a `sound` directory that contains the `critical` key.

Critical alerts require a special entitlement issued by Apple.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/criticalAlertSetting

func (UNNotificationSettings) EncodeWithCoder

func (u UNNotificationSettings) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationSettings) Init

Init initializes the instance.

func (UNNotificationSettings) LockScreenSetting

func (u UNNotificationSettings) LockScreenSetting() UNNotificationSetting

The setting that indicates whether your app’s notifications appear on a device’s Lock screen.

Discussion

Even if the user disables lock screen notifications, your notifications may still appear onscreen when the device is unlocked.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/lockScreenSetting

func (UNNotificationSettings) NotificationCenterSetting

func (u UNNotificationSettings) NotificationCenterSetting() UNNotificationSetting

The setting that indicates whether your app’s notifications appear in Notification Center.

Discussion

The default value of this property is UNNotificationSettingEnabled.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/notificationCenterSetting

func (UNNotificationSettings) ProvidesAppNotificationSettings

func (u UNNotificationSettings) ProvidesAppNotificationSettings() bool

A Boolean value indicating the system displays a button for in-app notification settings.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/providesAppNotificationSettings

func (UNNotificationSettings) ScheduledDeliverySetting

func (u UNNotificationSettings) ScheduledDeliverySetting() UNNotificationSetting

The setting that indicates the system schedules the notification.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/scheduledDeliverySetting

func (UNNotificationSettings) ShowPreviewsSetting

func (u UNNotificationSettings) ShowPreviewsSetting() UNShowPreviewsSetting

The setting that indicates whether the app shows a preview of the notification’s content.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/showPreviewsSetting

func (UNNotificationSettings) SoundSetting

The authorization status for playing sounds for incoming notifications.

Discussion

When the value of this property is UNNotificationSettingEnabled, the system authorizes the app to play sounds. The system tries to play a sound when the [Sound] property of the UNNotificationContent object contains a value, or when the `aps` dictionary in a remote notification contains the `sound` key.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/soundSetting

func (UNNotificationSettings) TimeSensitiveSetting

func (u UNNotificationSettings) TimeSensitiveSetting() UNNotificationSetting

The setting that indicates the system treats the notification as time-sensitive.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSettings/timeSensitiveSetting

type UNNotificationSettingsClass

type UNNotificationSettingsClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationSettingsClass

func GetUNNotificationSettingsClass() UNNotificationSettingsClass

GetUNNotificationSettingsClass returns the class object for UNNotificationSettings.

func (UNNotificationSettingsClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationSettingsClass) Class

Class returns the underlying Objective-C class pointer.

type UNNotificationSettingsHandler

type UNNotificationSettingsHandler = func(*UNNotificationSettings)

UNNotificationSettingsHandler handles The block to execute asynchronously with the results.

  • settings: The UNNotificationSettings(<doc://com.apple.usernotifications/documentation/UserNotifications/UNNotificationSettings>) object containing the current authorization settings for your app.

Used by:

type UNNotificationSound

type UNNotificationSound struct {
	objectivec.Object
}

The sound played upon delivery of a notification.

Overview

Create a UNNotificationSound object when you want the system to play a specific sound when it delivers with your notification. To play the default system sound, create your sound object using the [UNNotificationSound.DefaultSound] method. If you want to play a custom sound, create a new sound object and specify the name of the audio file that you want to play.

For local notifications, assign the sound object to the UNNotificationSound.Sound property of your UNMutableNotificationContent object. For a remote notification, assign the name of your sound file to the `sound` key in the `aps` dictionary. You can also use a notification service app extension to add a sound file to a notification shortly before delivery. In your extension, create a UNNotificationSound object and add it to your notification content in the same way that you’d for a local notification.

Audio files must already be on the user’s device before the system can play them. If you use a predefined set of sounds for your notifications, include the audio files in your app’s bundle. For all other sounds, the UNNotificationSound object looks only in the following locations:

- The `/Library/Sounds` directory of the app’s container directory. - The `/Library/Sounds` directory of one of the app’s shared group container directories. - The main bundle of the current executable.

Prepare Sound Resources

The system sound facility plays custom alert sounds, so they must be in one of the following audio data formats:

- Linear PCM - MA4 (IMA/ADPCM) - µLaw - aLaw

You can package the audio data in an `aiff`, `wav`, or `caf` file. Sound files must be less than 30 seconds in length. If the sound file is longer than 30 seconds, the system plays the default sound instead.

You can use the `afconvert` command-line tool to convert sounds. For example, to convert the system sound `Submarine.Aiff()` to IMA4 audio in a CAF file, use the following command in Terminal:

`afconvert /System/Library/Sounds/Submarine.Aiff() ~/Desktop/sub.Caf() -d ima4 -f caff -v`

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound

func NewUNNotificationSound

func NewUNNotificationSound() UNNotificationSound

NewUNNotificationSound creates a new UNNotificationSound instance.

func NewUNNotificationSoundNamed

func NewUNNotificationSoundNamed(name UNNotificationSoundName) UNNotificationSound

Creates a sound object that represents a custom sound file.

name: The name of the sound file to play. This parameter must not be `nil`.

Return Value

A sound object representing the custom sound.

Discussion

This method searches for sound files in the following locations, in order:

- The `/Library/Sounds` directory, where is the app’s container directory. - The `/Library/Sounds` directory, where is one of the app’s shared group container directories. For information about how to configure group containers for your app, see Configure app groups. - The main bundle of the current executable.

The method chooses the first file it finds with the specified name.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound/init(named:)

func UNNotificationSoundFromID

func UNNotificationSoundFromID(id objc.ID) UNNotificationSound

UNNotificationSoundFromID constructs a UNNotificationSound from an objc.ID.

The sound played upon delivery of a notification.

func (UNNotificationSound) Autorelease

func (u UNNotificationSound) Autorelease() UNNotificationSound

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationSound) EncodeWithCoder

func (u UNNotificationSound) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationSound) Init

Init initializes the instance.

func (UNNotificationSound) SetSound

func (u UNNotificationSound) SetSound(value IUNNotificationSound)

func (UNNotificationSound) Sound

The sound that plays when the system delivers the notification.

See: https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/sound

type UNNotificationSoundClass

type UNNotificationSoundClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationSoundClass

func GetUNNotificationSoundClass() UNNotificationSoundClass

GetUNNotificationSoundClass returns the class object for UNNotificationSound.

func (UNNotificationSoundClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationSoundClass) Class

func (uc UNNotificationSoundClass) Class() objc.Class

Class returns the underlying Objective-C class pointer.

func (UNNotificationSoundClass) CriticalSoundNamed

func (_UNNotificationSoundClass UNNotificationSoundClass) CriticalSoundNamed(name UNNotificationSoundName) UNNotificationSound

Creates a custom sound object for critical alerts.

name: The name of the sound file to play. This file must be located in the current executable’s main bundle or in the `Library/Sounds` directory of the current app container directory. If files exist at both locations, the system uses the file from the `Library/Sounds` directory. This parameter must not be `nil`.

Return Value

A sound object representing a custom critical alert sound.

Discussion

Critical alerts ignore the mute switch and Do Not Disturb. They require a special entitlement issued by Apple.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound/criticalSoundNamed(_:)

func (UNNotificationSoundClass) CriticalSoundNamedWithAudioVolume

func (_UNNotificationSoundClass UNNotificationSoundClass) CriticalSoundNamedWithAudioVolume(name UNNotificationSoundName, volume float32) UNNotificationSound

Creates a custom sound object for critical alerts with the volume you specify.

name: The name of the sound file to play. This file must be located in the current executable’s main bundle or in the `Library/Sounds` directory of the current app container directory. If files exist at both locations, the system uses the file from the `Library/Sounds` directory. This parameter must not be `nil`.

volume: The volume must be a value between 0.0 and 1.0.

Return Value

A sound object representing a custom critical alert sound at the specified volume.

Discussion

Critical alerts ignore the mute switch and Do Not Disturb. They require a special entitlement issued by Apple.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound/criticalSoundNamed(_:withAudioVolume:)

func (UNNotificationSoundClass) DefaultCriticalSound

func (_UNNotificationSoundClass UNNotificationSoundClass) DefaultCriticalSound() UNNotificationSound

The default sound used for critical alerts.

Discussion

Critical alerts ingore the mute switch and Do Not Disturb. They require a special entitlement issued by Apple.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound/defaultCritical

func (UNNotificationSoundClass) DefaultCriticalSoundWithAudioVolume

func (_UNNotificationSoundClass UNNotificationSoundClass) DefaultCriticalSoundWithAudioVolume(volume float32) UNNotificationSound

Creates a sound object that plays the default critical alert sound at the volume you specify.

volume: The volume must be a value between 0.0 and 1.0.

Return Value

A sound object representing the default critical alert sound at the specified volume.

Discussion

Critical alerts ignore the mute switch and Do Not Disturb. They require a special entitlement issued by Apple.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound/defaultCriticalSound(withAudioVolume:)

func (UNNotificationSoundClass) DefaultSound

func (_UNNotificationSoundClass UNNotificationSoundClass) DefaultSound() UNNotificationSound

Returns an object representing the default sound for notifications.

Return Value

A sound object that represents the default notification sound.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSound/default

type UNNotificationSoundName

type UNNotificationSoundName = string

UNNotificationSoundName is a string providing the name of a sound file.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationSoundName

type UNNotificationTrigger

type UNNotificationTrigger struct {
	objectivec.Object
}

The common behavior for subclasses that trigger the delivery of a local or remote notification.

Overview

The UNNotificationTrigger class is an abstract class for representing an event that triggers the delivery of a notification. You don’t create instances of this class directly. Instead, you instantiate the concrete subclass that defines the trigger condition you want for your notification. You then assign the resulting object to the UNNotificationRequest object that you use to schedule your notification.

Concrete trigger classes include the following:

- UNTimeIntervalNotificationTrigger - UNCalendarNotificationTrigger - UNLocationNotificationTrigger - UNPushNotificationTrigger

Configuring the Trigger’s Behavior

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationTrigger

func NewUNNotificationTrigger

func NewUNNotificationTrigger() UNNotificationTrigger

NewUNNotificationTrigger creates a new UNNotificationTrigger instance.

func UNNotificationTriggerFromID

func UNNotificationTriggerFromID(id objc.ID) UNNotificationTrigger

UNNotificationTriggerFromID constructs a UNNotificationTrigger from an objc.ID.

The common behavior for subclasses that trigger the delivery of a local or remote notification.

func (UNNotificationTrigger) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNNotificationTrigger) EncodeWithCoder

func (u UNNotificationTrigger) EncodeWithCoder(coder foundation.INSCoder)

func (UNNotificationTrigger) Init

Init initializes the instance.

func (UNNotificationTrigger) Repeats

func (u UNNotificationTrigger) Repeats() bool

A Boolean value indicating whether the system reschedules the notification after it’s delivered.

Discussion

When this property is false, the system delivers the notification only once. When this property is true, the system reschedules the notification request automatically, resulting in the system delivering the notification each time the trigger condition is met. To unschedule the notification request, use the methods of the UNUserNotificationCenter to remove the notification request.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationTrigger/repeats

type UNNotificationTriggerClass

type UNNotificationTriggerClass struct {
	// contains filtered or unexported fields
}

func GetUNNotificationTriggerClass

func GetUNNotificationTriggerClass() UNNotificationTriggerClass

GetUNNotificationTriggerClass returns the class object for UNNotificationTrigger.

func (UNNotificationTriggerClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNNotificationTriggerClass) Class

Class returns the underlying Objective-C class pointer.

type UNPushNotificationTrigger

type UNPushNotificationTrigger struct {
	UNNotificationTrigger
}

A trigger condition that indicates Apple Push Notification Service (APNs) has sent the notification.

Overview

You don’t create instances of this class yourself. The system creates UNPushNotificationTrigger objects and associates them with requests that originated from Apple Push Notification service. You encounter instances of this class when managing your app’s delivered notification requests, which store an object of this type in their UNPushNotificationTrigger.Trigger property.

See: https://developer.apple.com/documentation/UserNotifications/UNPushNotificationTrigger

func NewUNPushNotificationTrigger

func NewUNPushNotificationTrigger() UNPushNotificationTrigger

NewUNPushNotificationTrigger creates a new UNPushNotificationTrigger instance.

func UNPushNotificationTriggerFromID

func UNPushNotificationTriggerFromID(id objc.ID) UNPushNotificationTrigger

UNPushNotificationTriggerFromID constructs a UNPushNotificationTrigger from an objc.ID.

A trigger condition that indicates Apple Push Notification Service (APNs) has sent the notification.

func (UNPushNotificationTrigger) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNPushNotificationTrigger) Init

Init initializes the instance.

func (UNPushNotificationTrigger) SetTrigger

func (UNPushNotificationTrigger) Trigger

The conditions that trigger the delivery of the notification.

See: https://developer.apple.com/documentation/usernotifications/unnotificationrequest/trigger

type UNPushNotificationTriggerClass

type UNPushNotificationTriggerClass struct {
	// contains filtered or unexported fields
}

func GetUNPushNotificationTriggerClass

func GetUNPushNotificationTriggerClass() UNPushNotificationTriggerClass

GetUNPushNotificationTriggerClass returns the class object for UNPushNotificationTrigger.

func (UNPushNotificationTriggerClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNPushNotificationTriggerClass) Class

Class returns the underlying Objective-C class pointer.

type UNShowPreviewsSetting

type UNShowPreviewsSetting int

See: https://developer.apple.com/documentation/UserNotifications/UNShowPreviewsSetting

const (
	// UNShowPreviewsSettingAlways: The notification’s content is always shown, even when the device is locked.
	UNShowPreviewsSettingAlways UNShowPreviewsSetting = 0
	// UNShowPreviewsSettingNever: The notification’s content is never shown, even when the device is unlocked
	UNShowPreviewsSettingNever UNShowPreviewsSetting = 2
	// UNShowPreviewsSettingWhenAuthenticated: The notification’s content is shown only when the device is unlocked.
	UNShowPreviewsSettingWhenAuthenticated UNShowPreviewsSetting = 1
)

func (UNShowPreviewsSetting) String

func (e UNShowPreviewsSetting) String() string

type UNTextInputNotificationAction

type UNTextInputNotificationAction struct {
	UNNotificationAction
}

An action that accepts user-typed text.

Overview

Use UNTextInputNotificationAction objects to define an action that allows the user to provide a custom text-based response. When the user selects an action of this type, the system displays controls for the user to enter or dictate the text content. That text is then included in the response object that’s delivered to your app.

For information on how to define actions and categories, see Declaring your actionable notification types.

Getting Information

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationAction

func NewUNTextInputNotificationAction

func NewUNTextInputNotificationAction() UNTextInputNotificationAction

NewUNTextInputNotificationAction creates a new UNTextInputNotificationAction instance.

func NewUNTextInputNotificationActionWithIdentifierTitleOptions

func NewUNTextInputNotificationActionWithIdentifierTitleOptions(identifier string, title string, options UNNotificationActionOptions) UNTextInputNotificationAction

Creates an action object by using the specified title and options.

identifier: The string that you use internally to identify the action. This string must be unique among your app’s supported actions. When the user selects the action, the system passes this string to your app and asks the user to perform the related task. This parameter must not be `nil` or an empty string.

title: The localized string the system displays to the user. The system displays this string as the title of a button, which the system adds to the notification interface. This parameter must not be `nil`.

options: Additional options that describe how the action behaves. Include options when you need the related behavior. For a list of possible values, see UNNotificationActionOptions.

Return Value

An action object that the system initializes.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/init(identifier:title:options:)

func NewUNTextInputNotificationActionWithIdentifierTitleOptionsIcon

func NewUNTextInputNotificationActionWithIdentifierTitleOptionsIcon(identifier string, title string, options UNNotificationActionOptions, icon IUNNotificationActionIcon) UNTextInputNotificationAction

Creates an action object by using the specified title, options, and icon.

identifier: The string that you use internally to identify the action. This string must be unique among your app’s supported actions. When the user selects the action, the system passes this string to your app and asks the user to perform the related task. This parameter must not be `nil` or an empty string.

title: The localized string the system displays to the user. The system displays this string as the title of a button, which the system adds to the notification interface. This parameter must not be `nil`.

options: Additional options that describe how the action behaves. Include options when you need the related behavior. For a list of possible values, see UNNotificationActionOptions.

icon: The icon that the system displays to the user.

Return Value

An action object that the system initializes.

See: https://developer.apple.com/documentation/UserNotifications/UNNotificationAction/init(identifier:title:options:icon:)

func NewUNTextInputNotificationActionWithIdentifierTitleOptionsIconTextInputButtonTitleTextInputPlaceholder

func NewUNTextInputNotificationActionWithIdentifierTitleOptionsIconTextInputButtonTitleTextInputPlaceholder(identifier string, title string, options UNNotificationActionOptions, icon IUNNotificationActionIcon, textInputButtonTitle string, textInputPlaceholder string) UNTextInputNotificationAction

Creates an action object with an icon that accepts text input from the user.

identifier: The string that you use internally to identify the action. This string must be unique among all of your app’s supported actions. When the user selects the action, the system passes this string to your app and asks you to perform the related task. This parameter must not be `nil` or an empty string.

title: The localized string the system displays to the user. The system displays this string as the title of a button, which the system adds to the notification interface. This parameter must not be `nil`.

options: Additional options describing how the action behaves. Include options when you need the related behavior. For a list of possible values, see UNNotificationActionOptions.

icon: The icon to display to the user.

textInputButtonTitle: The localized title of the text input button that’s displayed to the user.

textInputPlaceholder: The localized placeholder text to display in the text input field.

Return Value

A new text input action object.

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationAction/init(identifier:title:options:icon:textInputButtonTitle:textInputPlaceholder:)

func NewUNTextInputNotificationActionWithIdentifierTitleOptionsTextInputButtonTitleTextInputPlaceholder

func NewUNTextInputNotificationActionWithIdentifierTitleOptionsTextInputButtonTitleTextInputPlaceholder(identifier string, title string, options UNNotificationActionOptions, textInputButtonTitle string, textInputPlaceholder string) UNTextInputNotificationAction

Creates an action object that accepts text input from the user.

identifier: The string that you use internally to identify the action. This string must be unique among all of your app’s supported actions. When the user selects the action, the system passes this string to your app and asks you to perform the related task. This parameter must not be `nil` or an empty string.

title: The localized string the system displays to the user. The system displays this string as the title of a button, which the system adds to the notification interface. This parameter must not be `nil`.

options: Additional options describing how the action behaves. Include options when you need the related behavior. For a list of possible values, see UNNotificationActionOptions.

textInputButtonTitle: The localized title of the text input button that’s displayed to the user.

textInputPlaceholder: The localized placeholder text the system displays in the text input field.

Return Value

A new text input action object.

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationAction/init(identifier:title:options:textInputButtonTitle:textInputPlaceholder:)

func UNTextInputNotificationActionFromID

func UNTextInputNotificationActionFromID(id objc.ID) UNTextInputNotificationAction

UNTextInputNotificationActionFromID constructs a UNTextInputNotificationAction from an objc.ID.

An action that accepts user-typed text.

func (UNTextInputNotificationAction) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNTextInputNotificationAction) Init

Init initializes the instance.

func (UNTextInputNotificationAction) TextInputButtonTitle

func (u UNTextInputNotificationAction) TextInputButtonTitle() string

The localized title of the text input button that the system displays to the user.

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationAction/textInputButtonTitle

func (UNTextInputNotificationAction) TextInputPlaceholder

func (u UNTextInputNotificationAction) TextInputPlaceholder() string

The placeholder text that the system localizes and displays in the text input field.

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationAction/textInputPlaceholder

type UNTextInputNotificationActionClass

type UNTextInputNotificationActionClass struct {
	// contains filtered or unexported fields
}

func GetUNTextInputNotificationActionClass

func GetUNTextInputNotificationActionClass() UNTextInputNotificationActionClass

GetUNTextInputNotificationActionClass returns the class object for UNTextInputNotificationAction.

func (UNTextInputNotificationActionClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNTextInputNotificationActionClass) Class

Class returns the underlying Objective-C class pointer.

type UNTextInputNotificationResponse

type UNTextInputNotificationResponse struct {
	UNNotificationResponse
}

The user’s response to an actionable notification, including any custom text that the user typed or dictated.

Overview

The system delivers a UNTextInputNotificationResponse object to your app so that you can process user-provided text content. When defining your categories, you can specify an UNTextInputNotificationAction object instead of an UNNotificationAction object for your action. If you do, the system creates an UNTextInputNotificationResponse object when the user selects the accompanying action, and it fills the UNTextInputNotificationResponse.UserText property with any user-entered text.

You don’t create UNTextInputNotificationResponse objects yourself. Instead, the shared user notification center object creates them and delivers them to the [UserNotificationCenterDidReceiveNotificationResponseWithCompletionHandler] method of its delegate object. Use that method to extract any needed information from the response object and take appropriate action.

For more information about responding to actions, see Handling notifications and notification-related actions.

Getting the Text Response

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationResponse

func NewUNTextInputNotificationResponse

func NewUNTextInputNotificationResponse() UNTextInputNotificationResponse

NewUNTextInputNotificationResponse creates a new UNTextInputNotificationResponse instance.

func UNTextInputNotificationResponseFromID

func UNTextInputNotificationResponseFromID(id objc.ID) UNTextInputNotificationResponse

UNTextInputNotificationResponseFromID constructs a UNTextInputNotificationResponse from an objc.ID.

The user’s response to an actionable notification, including any custom text that the user typed or dictated.

func (UNTextInputNotificationResponse) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNTextInputNotificationResponse) Init

Init initializes the instance.

func (UNTextInputNotificationResponse) UserText

The text response provided by the user.

Discussion

If the user does not specify any text, this property contains an empty string.

See: https://developer.apple.com/documentation/UserNotifications/UNTextInputNotificationResponse/userText

type UNTextInputNotificationResponseClass

type UNTextInputNotificationResponseClass struct {
	// contains filtered or unexported fields
}

func GetUNTextInputNotificationResponseClass

func GetUNTextInputNotificationResponseClass() UNTextInputNotificationResponseClass

GetUNTextInputNotificationResponseClass returns the class object for UNTextInputNotificationResponse.

func (UNTextInputNotificationResponseClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNTextInputNotificationResponseClass) Class

Class returns the underlying Objective-C class pointer.

type UNTimeIntervalNotificationTrigger

type UNTimeIntervalNotificationTrigger struct {
	UNNotificationTrigger
}

A trigger condition that causes the system to deliver a notification after the amount of time you specify elapses.

Overview

Create a UNTimeIntervalNotificationTrigger object when you want to schedule the delivery of a local notification after the number of seconds you specify elapses. You use this type of trigger to implement timers.

Listing 1 creates a trigger that delivers its notification one time after 30 minutes have elapsed.

Listing 1. Creating a trigger that fires in 30 minutes

Getting the Trigger Information

See: https://developer.apple.com/documentation/UserNotifications/UNTimeIntervalNotificationTrigger

func NewUNTimeIntervalNotificationTrigger

func NewUNTimeIntervalNotificationTrigger() UNTimeIntervalNotificationTrigger

NewUNTimeIntervalNotificationTrigger creates a new UNTimeIntervalNotificationTrigger instance.

func NewUNTimeIntervalNotificationTriggerWithTimeIntervalRepeats

func NewUNTimeIntervalNotificationTriggerWithTimeIntervalRepeats(timeInterval float64, repeats bool) UNTimeIntervalNotificationTrigger

Creates a time interval trigger using the time value parameter.

timeInterval: The time (in seconds) that must elapse from the current time before the trigger fires. This value must be greater than zero.

repeats: Specify false to deliver the notification one time. Specify true to reschedule the notification request each time the system delivers the notification. If this parameter is true, the value in the `timeInterval` parameter must be 60 seconds or greater.

Return Value

A new time interval trigger based on the specified temporal information.

Discussion

If you specify `true` for the `repeats` parameter, you must explicitly remove the notification request to stop the delivery of the associated notification. Use the methods of UNUserNotificationCenter to remove notification requests that are no longer needed.

See: https://developer.apple.com/documentation/UserNotifications/UNTimeIntervalNotificationTrigger/init(timeInterval:repeats:)

func UNTimeIntervalNotificationTriggerFromID

func UNTimeIntervalNotificationTriggerFromID(id objc.ID) UNTimeIntervalNotificationTrigger

UNTimeIntervalNotificationTriggerFromID constructs a UNTimeIntervalNotificationTrigger from an objc.ID.

A trigger condition that causes the system to deliver a notification after the amount of time you specify elapses.

func (UNTimeIntervalNotificationTrigger) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNTimeIntervalNotificationTrigger) Init

Init initializes the instance.

func (UNTimeIntervalNotificationTrigger) NextTriggerDate

The next date at which the trigger conditions are met.

Return Value

The next trigger date.

Discussion

Use this property to find out when a notification associated with this trigger will next be delivered.

See: https://developer.apple.com/documentation/UserNotifications/UNTimeIntervalNotificationTrigger/nextTriggerDate()

func (UNTimeIntervalNotificationTrigger) TimeInterval

func (u UNTimeIntervalNotificationTrigger) TimeInterval() float64

The time interval to create the trigger.

Discussion

This property contains the original time interval that you specified when creating the trigger object. The value in this property isn’t updated as time counts down. To find out when the trigger will fire next, call the [NextTriggerDate] method.

See: https://developer.apple.com/documentation/UserNotifications/UNTimeIntervalNotificationTrigger/timeInterval

type UNTimeIntervalNotificationTriggerClass

type UNTimeIntervalNotificationTriggerClass struct {
	// contains filtered or unexported fields
}

func GetUNTimeIntervalNotificationTriggerClass

func GetUNTimeIntervalNotificationTriggerClass() UNTimeIntervalNotificationTriggerClass

GetUNTimeIntervalNotificationTriggerClass returns the class object for UNTimeIntervalNotificationTrigger.

func (UNTimeIntervalNotificationTriggerClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNTimeIntervalNotificationTriggerClass) Class

Class returns the underlying Objective-C class pointer.

type UNUserNotificationCenter

type UNUserNotificationCenter struct {
	objectivec.Object
}

The central object for managing notification-related activities for your app or app extension.

Overview

Use the shared UNUserNotificationCenter object to manage all notification-related behaviors in your app or app extension. Specifically, use this object to do the following:

- Request authorization to interact with the user through alerts, sounds, and icon badges. See Asking permission to use notifications. - Declare the notification types that your app supports and the custom actions the user may perform when the system delivers those notifications. See Declaring your actionable notification types. - Schedule the delivery of notifications from your app. See Scheduling a notification locally from your app. - Process the payloads from remote notifications the system delivers by Apple Push Notification service (APNs). See Handling notifications and notification-related actions. - Manage the already delivered notifications the system displays in Notification Center. See Managing Delivered Notifications. - Handle user-selected actions associated with your custom notification types. See Handling notifications and notification-related actions. - Get the notification-related settings for your app. See Managing Settings and Authorization.

To handle incoming notifications and notification-related actions, create an object that adopts the UNUserNotificationCenterDelegate protocol and assign it to the UNUserNotificationCenter.Delegate property. Always assign an object to the UNUserNotificationCenter.Delegate property before performing any tasks that might interact with that delegate.

You may use the shared user notification center object simultaneously from any of your app’s threads. The object processes requests serially in the order that the system initiates them.

Managing the notification center

Requesting authorization

Processing received notifications

Scheduling notifications

Removing delivered notifications

Managing notification categories

Handling errors

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter

func NewUNUserNotificationCenter

func NewUNUserNotificationCenter() UNUserNotificationCenter

NewUNUserNotificationCenter creates a new UNUserNotificationCenter instance.

func UNUserNotificationCenterFromID

func UNUserNotificationCenterFromID(id objc.ID) UNUserNotificationCenter

UNUserNotificationCenterFromID constructs a UNUserNotificationCenter from an objc.ID.

The central object for managing notification-related activities for your app or app extension.

func (UNUserNotificationCenter) AddNotificationRequest

func (u UNUserNotificationCenter) AddNotificationRequest(ctx context.Context, request IUNNotificationRequest) error

AddNotificationRequest is a synchronous wrapper around UNUserNotificationCenter.AddNotificationRequestWithCompletionHandler. It blocks until the completion handler fires or the context is cancelled.

func (UNUserNotificationCenter) AddNotificationRequestWithCompletionHandler

func (u UNUserNotificationCenter) AddNotificationRequestWithCompletionHandler(request IUNNotificationRequest, completionHandler ErrorHandler)

Schedules the delivery of a local notification.

request: The request object containing the notification payload and trigger information. This parameter must not be `nil`.

completionHandler: The block to execute with the results. This block may be executed on a background thread. The block has no return value and takes the following parameter:

error: An error object indicating whether a problem occurred. If the notification was scheduled successfully, this parameter is `nil`; otherwise, it is set to an error object indicating the reason for the failure.

Discussion

This method schedules local notifications only; you cannot use it to schedule the delivery of remote notifications. Upon calling this method, the system begins tracking the trigger conditions associated with your request. When the trigger condition is met, the system delivers your notification. If the request does not contain a UNNotificationTrigger object, the notification is delivered right away.

You may call this method from any thread of your app.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/add(_:withCompletionHandler:)

func (UNUserNotificationCenter) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (UNUserNotificationCenter) Delegate

The notification center’s delegate.

Discussion

Use the delegate object to respond to user-selected actions and to process incoming notifications when your app is in the foreground. For example, you might use your delegate to silence notifications when your app is in the foreground.

To guarantee that your app responds to all actionable notifications, you must set the value of this property before your app finishes launching. For an iOS app, this means updating this property in the application(_:willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions:) method of the app delegate. Notifications that cause your app to be launched or delivered shortly after these methods finish executing.

For more information about implementing the delegate methods, see UNUserNotificationCenterDelegate.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/delegate

func (UNUserNotificationCenter) GetNotificationSettings

func (u UNUserNotificationCenter) GetNotificationSettings(ctx context.Context) (*UNNotificationSettings, error)

GetNotificationSettings is a synchronous wrapper around UNUserNotificationCenter.GetNotificationSettingsWithCompletionHandler. It blocks until the completion handler fires or the context is cancelled.

func (UNUserNotificationCenter) GetNotificationSettingsWithCompletionHandler

func (u UNUserNotificationCenter) GetNotificationSettingsWithCompletionHandler(completionHandler UNNotificationSettingsHandler)

Retrieves the authorization and feature-related settings for your app.

completionHandler: The block to execute asynchronously with the results. Your app may execute this block on a background thread. The block has no return value and takes the following parameter:

settings: The UNNotificationSettings object containing the current authorization settings for your app.

Discussion

Use this method to determine the user interactions and notification-related features that the system authorizes your app to use. You might then use this information to enable or disable specific notification-related features of your app.

When the user initially grants authorization to your app, the system gives your app a set of default notification-related settings. The user may change those settings at any time to enable or disable specific capabilities. For example, the user might disable the playing of sounds when a notification arrives.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/getNotificationSettings(completionHandler:)

func (UNUserNotificationCenter) Init

Init initializes the instance.

func (UNUserNotificationCenter) RemoveAllDeliveredNotifications

func (u UNUserNotificationCenter) RemoveAllDeliveredNotifications()

Removes all of your app’s delivered notifications from Notification Center.

Discussion

Use this method to remove all of your app’s delivered notifications from Notification Center. The method executes asynchronously, returning immediately and removing the identifiers on a background thread. This method does not affect any notification requests that are scheduled, but have not yet been delivered.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/removeAllDeliveredNotifications()

func (UNUserNotificationCenter) RemoveAllPendingNotificationRequests

func (u UNUserNotificationCenter) RemoveAllPendingNotificationRequests()

Removes all of your app’s pending local notifications.

Discussion

This method executes asynchronously, removing all pending notification requests on a secondary thread.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/removeAllPendingNotificationRequests()

func (UNUserNotificationCenter) RemoveDeliveredNotificationsWithIdentifiers

func (u UNUserNotificationCenter) RemoveDeliveredNotificationsWithIdentifiers(identifiers []string)

Removes your app’s notifications from Notification Center that match the specified identifiers.

identifiers: An array of NSString objects, each of which corresponds to a value in the [Identifier] property of a UNNotificationRequest object. This method ignores the identifiers of requests whose notifications are not currently displayed in Notification Center.

Discussion

Use this method to selectively remove notifications that you no longer want displayed in Notification Center. The method executes asynchronously, returning immediately and removing the specified notifications on a background thread.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/removeDeliveredNotifications(withIdentifiers:)

func (UNUserNotificationCenter) RemovePendingNotificationRequestsWithIdentifiers

func (u UNUserNotificationCenter) RemovePendingNotificationRequestsWithIdentifiers(identifiers []string)

Removes your app’s local notifications that are pending and match the specified identifiers.

identifiers: An array of NSString objects, each of which contains the [Identifier] of an active UNNotificationRequest object. If the identifier belongs to a non repeating request, and the trigger condition for that request has already been met, this method ignores the identifier.

Discussion

This method executes asynchronously, removing the pending notification requests on a secondary thread.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/removePendingNotificationRequests(withIdentifiers:)

func (UNUserNotificationCenter) RequestAuthorizationWithOptions

func (u UNUserNotificationCenter) RequestAuthorizationWithOptions(ctx context.Context, options UNAuthorizationOptions) (bool, error)

RequestAuthorizationWithOptions is a synchronous wrapper around UNUserNotificationCenter.RequestAuthorizationWithOptionsCompletionHandler. It blocks until the completion handler fires or the context is cancelled.

func (UNUserNotificationCenter) RequestAuthorizationWithOptionsCompletionHandler

func (u UNUserNotificationCenter) RequestAuthorizationWithOptionsCompletionHandler(options UNAuthorizationOptions, completionHandler BoolErrorHandler)

Requests a person’s authorization to allow local and remote notifications for your app.

options: The authorization options your app is requesting. You may combine the available constants to request authorization for multiple items. Request only the authorization options that you plan to use. For a list of possible values, see UNAuthorizationOptions.

completionHandler: The block to execute asynchronously with the results. This block may execute on a background thread. The block has no return value and has the following parameters:

granted: A Boolean value indicating whether the person grants authorization. The value of this parameter is true when the person grants authorization for one or more options. The value is false when the person denies authorization or authorization is undetermined. Use [GetNotificationSettingsWithCompletionHandler] to check the authorization status. error: An object containing error information or `nil` if no error occurs.

Discussion

If your app’s local or remote notifications involve user interactions, you must request authorization for the system to perform those interactions on your app’s behalf. Interactions include displaying an alert, playing a sound, or badging the app’s icon.

The first time your app calls the method, the system prompts the person to authorize the requested interactions. The person may grant or deny authorization, and the system stores the person’s response. Subsequent calls to this method don’t prompt the person again. After determining the authorization status, the user notification center object executes the block in the `completionHandler` parameter. Use that block to make any adjustments to your app’s behavior. For example, if the person denied authorization, you might notify a remote notification server not to send notifications to the user’s device.

The person may change the interactions they allow at any time in system settings. Use the [GetNotificationSettingsWithCompletionHandler] method to determine what interactions are allowed for your app.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/requestAuthorization(options:completionHandler:)

func (UNUserNotificationCenter) SetBadgeCount

func (u UNUserNotificationCenter) SetBadgeCount(ctx context.Context, newBadgeCount int) error

SetBadgeCount is a synchronous wrapper around UNUserNotificationCenter.SetBadgeCountWithCompletionHandler. It blocks until the completion handler fires or the context is cancelled.

func (UNUserNotificationCenter) SetBadgeCountWithCompletionHandler

func (u UNUserNotificationCenter) SetBadgeCountWithCompletionHandler(newBadgeCount int, completionHandler ErrorHandler)

Updates the badge count for your app’s icon.

newBadgeCount: The new value to display.

completionHandler: The handler to execute after the update finishes. If the update fails, the system provides an error that contains additional information about the failure.

Discussion

Here’s an example that sets the badge count to a specific number.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/setBadgeCount(_:withCompletionHandler:)

func (UNUserNotificationCenter) SetDelegate

func (UNUserNotificationCenter) SetNotificationCategories

func (u UNUserNotificationCenter) SetNotificationCategories(categories foundation.INSSet)

Registers the notification categories that your app supports.

categories: A set of UNNotificationCategory objects, each of which contains the actions that are displayed with the notification interface. This parameter must contain all of your app’s supported categories.

Discussion

Call this method at launch time to register your app’s actionable notification types. This method registers all of your categories at once, replacing any previously registered categories with the new ones in the `categories` parameter. Typically, you call this method only once.

Each object in the `categories` parameter contains a string for identifying the notification’s type. It also contains one or more custom actions that the user may perform in response to notifications of that type. When the system displays an alert for a notification, it looks in the notification payload for one of the identifier strings from your category objects. If it finds one, it adds user-selectable buttons for each action associated with that category object. Tapping a button notifies your app of the selected action, without bringing your app to the foreground.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/setNotificationCategories(_:)

func (UNUserNotificationCenter) SupportsContentExtensions

func (u UNUserNotificationCenter) SupportsContentExtensions() bool

A Boolean value that indicates whether the device supports notification content extensions.

Discussion

Notification content extensions let you customize the appearance of the alerts displayed for your app’s notifications. The value of this property is true for devices that support notification content extensions and false for devices that do not support them. For information about how to implement a notification content extension, see Customizing the Appearance of Notifications.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/supportsContentExtensions

func (UNUserNotificationCenter) UNErrorDomain

func (u UNUserNotificationCenter) UNErrorDomain() string

The error domain for notifications.

See: https://developer.apple.com/documentation/usernotifications/unerrordomain

type UNUserNotificationCenterClass

type UNUserNotificationCenterClass struct {
	// contains filtered or unexported fields
}

func GetUNUserNotificationCenterClass

func GetUNUserNotificationCenterClass() UNUserNotificationCenterClass

GetUNUserNotificationCenterClass returns the class object for UNUserNotificationCenter.

func (UNUserNotificationCenterClass) Alloc

Alloc allocates memory for a new instance of the class.

func (UNUserNotificationCenterClass) Class

Class returns the underlying Objective-C class pointer.

func (UNUserNotificationCenterClass) CurrentNotificationCenter

func (_UNUserNotificationCenterClass UNUserNotificationCenterClass) CurrentNotificationCenter() UNUserNotificationCenter

Returns your app’s notification center.

Return Value

The notification center object to use.

Discussion

Always use this method to retrieve the shared notification center object for your app. Do not try to create instances of the UNUserNotificationCenter class directly.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenter/current()

type UNUserNotificationCenterDelegate

type UNUserNotificationCenterDelegate interface {
	objectivec.IObject
}

An interface for processing incoming notifications and responding to notification actions.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenterDelegate

type UNUserNotificationCenterDelegateConfig

type UNUserNotificationCenterDelegateConfig struct {

	// Other Methods
	// UserNotificationCenterOpenSettingsForNotification — Asks the delegate to display the in-app notification settings.
	UserNotificationCenterOpenSettingsForNotification func(center UNUserNotificationCenter, notification UNNotification)
}

UNUserNotificationCenterDelegateConfig holds optional typed callbacks for UNUserNotificationCenterDelegate methods. Set non-nil fields to register the corresponding Objective-C delegate method. Methods with nil callbacks are not registered, so [NSObject.RespondsToSelector] returns false for them — matching the Objective-C delegate pattern exactly.

See Apple Documentation for protocol details.

type UNUserNotificationCenterDelegateObject

type UNUserNotificationCenterDelegateObject struct {
	objectivec.Object
}

UNUserNotificationCenterDelegateObject wraps an existing Objective-C object that conforms to the UNUserNotificationCenterDelegate protocol.

func NewUNUserNotificationCenterDelegate

func NewUNUserNotificationCenterDelegate(config UNUserNotificationCenterDelegateConfig) UNUserNotificationCenterDelegateObject

NewUNUserNotificationCenterDelegate creates an Objective-C object implementing the UNUserNotificationCenterDelegate protocol.

Each call registers a unique Objective-C class containing only the methods set in config. This means [NSObject.RespondsToSelector] works correctly for optional delegate methods — only non-nil callbacks are registered.

The returned UNUserNotificationCenterDelegateObject satisfies the UNUserNotificationCenterDelegate interface and can be passed directly to SetDelegate and similar methods.

See Apple Documentation for protocol details.

func UNUserNotificationCenterDelegateObjectFromID

func UNUserNotificationCenterDelegateObjectFromID(id objc.ID) UNUserNotificationCenterDelegateObject

UNUserNotificationCenterDelegateObjectFromID constructs a UNUserNotificationCenterDelegateObject from an objc.ID. The object is determined to conform to the protocol at runtime.

func (UNUserNotificationCenterDelegateObject) BaseObject

func (UNUserNotificationCenterDelegateObject) UserNotificationCenterDidReceiveNotificationResponseWithCompletionHandler

func (o UNUserNotificationCenterDelegateObject) UserNotificationCenterDidReceiveNotificationResponseWithCompletionHandler(center IUNUserNotificationCenter, response IUNNotificationResponse, completionHandler VoidHandler)

Asks the delegate to process the user’s response to a delivered notification.

center: The shared user notification center object that received the notification.

response: The user’s response to the notification. This object contains the original notification and the identifier string for the selected action. If the action allowed the user to provide a textual response, this parameter contains a UNTextInputNotificationResponse object.

completionHandler: The block to execute when you have finished processing the user’s response. You must execute this block at some point after processing the user’s response to let the system know that you are done. The block has no return value or parameters.

Discussion

Use this method to process the user’s response to a notification. If the user selected one of your app’s custom actions, the `response` parameter contains the identifier for that action. (The response can also indicate that the user dismissed the notification interface, or launched your app, without selecting a custom action.) At the end of your implementation, call the `completionHandler` block to let the system know that you are done processing the user’s response. If you do not implement this method, your app never responds to custom actions.

You specify your app’s notification types at app launch using UNNotificationCategory objects, and you specify the custom actions for each type using UNNotificationAction objects. For information, see Declaring your actionable notification types.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenterDelegate/userNotificationCenter(_:didReceive:withCompletionHandler:)

func (UNUserNotificationCenterDelegateObject) UserNotificationCenterOpenSettingsForNotification

func (o UNUserNotificationCenterDelegateObject) UserNotificationCenterOpenSettingsForNotification(center IUNUserNotificationCenter, notification IUNNotification)

Asks the delegate to display the in-app notification settings.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenterDelegate/userNotificationCenter(_:openSettingsFor:)

func (UNUserNotificationCenterDelegateObject) UserNotificationCenterWillPresentNotificationWithCompletionHandler

func (o UNUserNotificationCenterDelegateObject) UserNotificationCenterWillPresentNotificationWithCompletionHandler(center IUNUserNotificationCenter, notification IUNNotification, completionHandler UNNotificationPresentationOptionsHandler)

Asks the delegate how to handle a notification that arrived while the app was running in the foreground.

center: The shared user notification center object that received the notification.

notification: The notification that is about to be delivered. Use the information in this object to determine an appropriate course of action. For example, you might use the information to update your app’s interface.

completionHandler: The block to execute with the presentation option for the notification. Always execute this block at some point during your implementation of this method. Use the `options` parameter to specify how you want the system to alert the user, if at all. This block has no return value and takes the following parameter:

options: The option for notifying the user. Specify UNNotificationPresentationOptionNone to silence the notification completely. Specify other values to interact with the user. For a list of possible options, see UNNotificationPresentationOptions.

Discussion

If your app is in the foreground when a notification arrives, the shared user notification center calls this method to deliver the notification directly to your app. If you implement this method, you can take whatever actions are necessary to process the notification and update your app. When you finish, call the `completionHandler` block and specify how you want the system to alert the user, if at all.

If your delegate does not implement this method, the system behaves as if you had passed the UNNotificationPresentationOptionNone option to the `completionHandler` block. If you do not provide a delegate at all for the UNUserNotificationCenter object, the system uses the notification’s original options to alert the user.

See: https://developer.apple.com/documentation/UserNotifications/UNUserNotificationCenterDelegate/userNotificationCenter(_:willPresent:withCompletionHandler:)

type VoidHandler

type VoidHandler = func()

VoidHandler handles The block to execute when you have finished processing the user’s response.

Used by:

  • [UNUserNotificationCenterDelegate.UserNotificationCenterDidReceiveNotificationResponseWithCompletionHandler]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL