### Example Usage Source: https://developer.apple.com/documentation/usernotifications/unnotificationrequest An example demonstrating how to create a UNNotificationRequest with content and a time interval trigger. ```swift // Create a content object with the message to convey. let content = UNMutableNotificationContent() content.title = "Lunch time" content.body = "Food is cooked... let\'s eat!" // Create a notification trigger for 60 seconds in the future. let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60.0, repeats: false) // Create the request with the content and the trigger. let request = UNNotificationRequest(identifier: "com.example.mynotification", content: content, trigger: trigger) ``` -------------------------------- ### Example: Set Badge Count to a Specific Number Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/setbadgecount%28_%3Awithcompletionhandler%3A%29 This example demonstrates how to set the app's badge count to a specific number using the asynchronous `setBadgeCount` method. Ensure you handle potential errors during the update process. ```swift let center = UNUserNotificationCenter.current() do { // Set the badge count to 3. try await center.setBadgeCount(3) } catch { // Handle any errors. } ``` -------------------------------- ### Getting the Options Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory Property to retrieve the options for how to handle notifications associated with this category. ```APIDOC ## Getting the Options ### `var options: UNNotificationCategoryOptions` Options for how to handle notifications of this type. ### `struct UNNotificationCategoryOptions` Constants indicating how to handle notifications associated with this category. ``` -------------------------------- ### Getting the Options Source: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory Properties and structures related to notification category options. ```APIDOC ## Getting the Options ### `var options: UNNotificationCategoryOptions` Options for how to handle notifications of this type. ### `struct UNNotificationCategoryOptions` Constants indicating how to handle notifications associated with this category. ``` -------------------------------- ### Getting the Information Source: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory Properties to retrieve information about the notification category. ```APIDOC ## Getting the Information ### `var identifier: String` The unique string assigned to the category. ### `var actions: [UNNotificationAction]` The actions to display when the system delivers notifications of this type. ### `var intentIdentifiers: [String]` The intents related to notifications of this category. ### `var hiddenPreviewsBodyPlaceholder: String` The placeholder text to display when the system disables notification previews for the app. ### `var categorySummaryFormat: String` A format string for the summary description used when the system groups the category’s notifications. ``` -------------------------------- ### Create a time interval trigger Source: https://developer.apple.com/documentation/usernotifications/untimeintervalnotificationtrigger Examples for initializing a trigger that fires after 30 minutes in both Swift and Objective-C. ```swift // Fire in 30 minutes (60 seconds times 30) let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (30*60), repeats: false) ``` ```objective-c // Fire in 30 minutes (60 seconds times 30) UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:(30*60) repeats: NO]; ``` -------------------------------- ### Inspect Notification Settings Asynchronously Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/getnotificationsettings%28completionhandler%3A%29 Example of using the asynchronous notificationSettings method to retrieve and act upon current app settings. ```swift let center = UNUserNotificationCenter.current() let settings = await center.notificationSettings() // Add code here to inspect or act on the settings. ``` -------------------------------- ### Scheduling a Local Notification Source: https://developer.apple.com/documentation/UserNotifications/UNMutableNotificationContent This example demonstrates how to create a UNMutableNotificationContent object, configure its properties, and schedule a local notification to be delivered after a delay. ```APIDOC ## Scheduling a Local Notification ### Description This code snippet shows how to create and configure a `UNMutableNotificationContent` object and schedule a local notification. ### Method This is an SDK example, not an HTTP endpoint. ### Parameters This example does not involve direct parameter passing in the traditional sense, but rather setting properties on the `UNMutableNotificationContent` object. ### Request Example ```swift // Configure the notification's payload. let content = UNMutableNotificationContent() content.title = NSString.localizedUserNotificationString(forKey: "Hello!", arguments: nil) content.body = NSString.localizedUserNotificationString(forKey: "Hello_message_body", arguments: nil) content.sound = UNNotificationSound.default // Deliver the notification in five seconds. let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) let request = UNNotificationRequest(identifier: "FiveSecond", content: content, trigger: trigger) // Schedule the notification. let center = UNUserNotificationCenter.current() center.add(request) { (error : Error?) in if let theError = error { // Handle any errors } } ``` ### Response This is an SDK operation, not an HTTP request/response. #### Success Response No specific success response is detailed, but the `center.add` method includes an optional error parameter. #### Response Example ```swift // Handle any errors if let theError = error { print("Error scheduling notification: \(theError.localizedDescription)") } ``` ``` ```APIDOC ## Scheduling a Local Notification (Objective-C) ### Description This Objective-C code snippet demonstrates how to create and configure a `UNMutableNotificationContent` object and schedule a local notification. ### Method This is an SDK example, not an HTTP endpoint. ### Parameters This example does not involve direct parameter passing in the traditional sense, but rather setting properties on the `UNMutableNotificationContent` object. ### Request Example ```objectivec // Configure the notification's payload. UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.title = [NSString localizedUserNotificationStringForKey:@"Hello!" arguments:nil]; content.body = [NSString localizedUserNotificationStringForKey:@"Hello_message_body" arguments:nil]; content.sound = [UNNotificationSound defaultSound]; // Deliver the notification in five seconds. UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:5 repeats:NO]; UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" content:content trigger:trigger]; // Schedule the notification. UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; [center addNotificationRequest:request]; ``` ### Response This is an SDK operation, not an HTTP request/response. #### Success Response No specific success response is detailed for the `addNotificationRequest` method in this context. #### Response Example Error handling would typically be managed through delegate methods or completion handlers if provided by the SDK, but is not explicitly shown in this basic scheduling example. ``` -------------------------------- ### Request Authorization Asynchronous Implementation Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/requestauthorization%28options%3Acompletionhandler%3A%29 An example of calling the requestAuthorization method using the async/await pattern. ```swift let center = UNUserNotificationCenter.current() do { if try await center.requestAuthorization(options: [.badge, .sound, .alert]) == true { // You have authorization. } else { // You don't have authorization. } } catch { // Handle any errors. } ``` -------------------------------- ### Error Response Example Source: https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns This code listing shows a sample response when an error occurs during push notification delivery. ```APIDOC ## Error Response Example ### Description This example demonstrates an HTTP/2 response from APNs indicating an error, specifically a bad device token. ### Method N/A (This is a response example) ### Endpoint N/A (This is a response example) ### Response #### Error Response (400) - **status** (integer) - The HTTP status code, 400 for client errors. - **content-type** (string) - The content type of the response body, typically application/json. - **apns-id** (string) - A unique identifier for the push notification. #### Response Example ```http :status = 400 content-type = application/json apns-id: { "reason" : "BadDeviceToken" } ``` ``` -------------------------------- ### Reading system configuration Source: https://developer.apple.com/documentation/usernotifications/unnotificationcontent Get information about the notification's sound, importance, and how it's scored or filtered by the system. ```APIDOC ## Reading system configuration ### `sound` `var sound: UNNotificationSound?` The sound that plays when the system delivers the notification. ### `interruptionLevel` `var interruptionLevel: UNNotificationInterruptionLevel` The notification’s importance and required delivery timing. ### `relevanceScore` `var relevanceScore: Double` The score the system uses to determine if the notification is the summary’s featured notification. ### `filterCriteria` `var filterCriteria: String?` The criteria the system evaluates to determine if it displays the notification in the current Focus. ``` -------------------------------- ### Getting the Information Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory Properties to retrieve information about a UNNotificationCategory, including its identifier, actions, intent identifiers, placeholder text, and summary format. ```APIDOC ## Getting the Information ### `var identifier: String` The unique string assigned to the category. ### `var actions: [UNNotificationAction]` The actions to display when the system delivers notifications of this type. ### `var intentIdentifiers: [String]` The intents related to notifications of this category. ### `var hiddenPreviewsBodyPlaceholder: String` The placeholder text to display when the system disables notification previews for the app. ### `var categorySummaryFormat: String` A format string for the summary description used when the system groups the category’s notifications. ``` -------------------------------- ### Getting Notification Settings Source: https://developer.apple.com/documentation/usernotifications/unnotificationsettings You don’t create instances of this class directly. Instead, call the getNotificationSettings(completionHandler:) method of your app’s UNUserNotificationCenter object to get the current settings. ```APIDOC ## Get Notification Settings ### Description Retrieves the current notification settings for the app. ### Method `getNotificationSettings(completionHandler:)` ### Parameters #### Completion Handler - **completionHandler** (function) - A block that executes when the settings are retrieved. It receives a `UNNotificationSettings` object containing the current settings. ### Response #### Success Response - **UNNotificationSettings** (object) - An object containing the app's current notification settings. ``` -------------------------------- ### init(identifier:title:options:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationaction/init%28identifier%3Atitle%3Aoptions%3A%29 Creates an action object by using the specified title and options. ```APIDOC ## init(identifier:title:options:) ### Description Creates an action object by using the specified title and options. ### Method Initializer ### Parameters - **identifier** (String) - Required - The string that you use internally to identify the action. This string must be unique among your app’s supported actions. - **title** (String) - Required - The localized string the system displays to the user as the title of a button. - **options** (UNNotificationActionOptions) - Optional - Additional options that describe how the action behaves. ### Request Example convenience init( identifier: String, title: String, options: UNNotificationActionOptions = [] ) ### Response - **Return Value** (UNNotificationAction) - An action object that the system initializes. ``` -------------------------------- ### init(named:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationsound/init%28named%3A%29 Creates a sound object that represents a custom sound file for notifications. ```APIDOC ## init(named:) ### Description Creates a sound object that represents a custom sound file. ### Parameters #### Path Parameters - **name** (UNNotificationSoundName) - Required - The name of the sound file to play. ### Return Value A sound object representing the custom sound. ### Discussion This method searches for sound files in the following locations, in order: 1. The /Library/Sounds directory. 2. The /Library/Sounds directory. 3. The main bundle of the current executable. The method chooses the first file it finds with the specified name. ``` -------------------------------- ### init(identifier:title:options:icon:textInputButtonTitle:textInputPlaceholder:) Source: https://developer.apple.com/documentation/usernotifications/untextinputnotificationaction/init%28identifier%3Atitle%3Aoptions%3Aicon%3Atextinputbuttontitle%3Atextinputplaceholder%3A%29 Creates an action object with an icon that accepts text input from the user. ```APIDOC ## init(identifier:title:options:icon:textInputButtonTitle:textInputPlaceholder:) ### Description Creates an action object with an icon that accepts text input from the user. ### Parameters - **identifier** (String) - Required - The string that you use internally to identify the action. Must be unique and not empty. - **title** (String) - Required - The localized string the system displays to the user as the button title. - **options** (UNNotificationActionOptions) - Optional - Additional options describing how the action behaves. - **icon** (UNNotificationActionIcon?) - Optional - The icon to display to the user. - **textInputButtonTitle** (String) - Required - The localized title of the text input button. - **textInputPlaceholder** (String) - Required - The localized placeholder text to display in the text input field. ### Return Value A new text input action object. ``` -------------------------------- ### GET UNNotificationAction.options Source: https://developer.apple.com/documentation/usernotifications/unnotificationaction/options Retrieves the behaviors associated with a notification action. ```APIDOC ## Property: options ### Description The behaviors associated with the action. Your app should define options for an action when your app requires the corresponding behavior. ### Declaration `var options: UNNotificationActionOptions { get }` ### Availability - iOS 10.0+ - iPadOS 10.0+ - Mac Catalyst 13.1+ - macOS 10.14+ - visionOS 1.0+ - watchOS 3.0+ ### See Also - UNNotificationActionOptions: The behaviors you can apply to an action. ``` -------------------------------- ### init(rawValue:) Source: https://developer.apple.com/documentation/usernotifications/unerror/code/init%28rawvalue%3A%29 Initializes a UNError.Code instance from a raw integer value. ```APIDOC ## init(rawValue:) ### Description Creates an instance of UNError.Code from a raw integer value. ### Method Initializer ### Parameters #### Request Body - **rawValue** (Int) - Required - The raw integer value representing the error code. ### Request Example init?(rawValue: 1) ### Response #### Success Response (200) - **instance** (UNError.Code?) - Returns an optional UNError.Code instance if the raw value is valid. ``` -------------------------------- ### Implement mediaPlay() for Media Playback Source: https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension/mediaplay%28%29 Implement this method to initiate media playback when the user taps the play button. Do not call this method directly; the system invokes it. ```swift optional func mediaPlay() ``` -------------------------------- ### GET current() Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/current%28%29 Retrieves the shared notification center object for the application. ```APIDOC ## GET current() ### Description Returns your app’s notification center. 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. ### Method class func ### Return Value - **UNUserNotificationCenter** - The notification center object to use. ``` -------------------------------- ### GET UNNotificationSound.default Source: https://developer.apple.com/documentation/usernotifications/unnotificationsound/default Retrieves the default notification sound object for the application. ```APIDOC ## GET UNNotificationSound.default ### Description Returns an object representing the default sound for notifications. ### Method Class Property (Getter) ### Return Value - **UNNotificationSound** - A sound object that represents the default notification sound. ``` -------------------------------- ### init(systemImageName:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationactionicon/init%28systemimagename%3A%29 Initializes a new notification action icon using a system symbol name. ```APIDOC ## init(systemImageName:) ### Description Creates an action icon by using a system symbol image. ### Parameters #### Parameters - **systemImageName** (String) - Required - The name of the system symbol image. Use the SF Symbols app to look up the names of system symbol images. ### Return Value An action icon that the system initializes with the system symbol image that your app specifies. ``` -------------------------------- ### Configure and Register Categories Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/setnotificationcategories%28_%3A%29 Demonstrates creating a notification category and registering it with the shared notification center instance. ```swift let center = UNUserNotificationCenter.current() let category1 = UNNotificationCategory(identifier: "com.example.mynotification", actions: [], intentIdentifiers: []) center.setNotificationCategories([category1]) center.removeAllPendingNotificationRequests() ``` -------------------------------- ### GET directMessagesSetting Source: https://developer.apple.com/documentation/usernotifications/unnotificationsettings/directmessagessetting Retrieves the current notification setting for direct messages. ```APIDOC ## directMessagesSetting ### Description A property that indicates the notification setting for direct messages. ### Availability - iOS 15.0+ - iPadOS 15.0+ - Mac Catalyst 15.0+ - macOS 12.0+ - visionOS 1.0+ - watchOS 8.0+ ### Declaration `var directMessagesSetting: UNNotificationSetting { get }` ``` -------------------------------- ### GET UNNotificationContent.threadIdentifier Source: https://developer.apple.com/documentation/usernotifications/unnotificationcontent/threadidentifier Retrieves the identifier used to group related notifications. ```APIDOC ## Property: threadIdentifier ### Description The identifier that groups related notifications. ### Declaration `var threadIdentifier: String { get }` ### Discussion For remote notifications, the system sets this property to the value of the `thread-id` key in the `aps` dictionary. ### Availability - iOS 10.0+ - iPadOS 10.0+ - Mac Catalyst 13.1+ - macOS 10.14+ - visionOS 1.0+ - watchOS 3.0+ ``` -------------------------------- ### init(rawValue:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationactionoptions/init%28rawvalue%3A%29 Initializes an action options object using the specified raw value. ```APIDOC ## init(rawValue:) ### Description Initializes an action options object using the specified raw value. ### Parameters #### Path Parameters - **rawValue** (UInt) - Required - The raw unsigned integer value for the action options. ### Request Example init(rawValue: 1) ``` -------------------------------- ### GET errorDomain Source: https://developer.apple.com/documentation/usernotifications/unerror/errordomain Retrieves the error domain string for notification errors. ```APIDOC ## GET errorDomain ### Description The errorDomain property provides the domain string used to identify errors within the User Notifications framework. ### Method GET ### Endpoint UNError.errorDomain ### Response - **errorDomain** (String) - The error domain for notifications. ``` -------------------------------- ### Initialize UNNotificationCategory without hidden preview placeholder Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory/init%28identifier%3Aactions%3Aintentidentifiers%3Ahiddenpreviewsbodyplaceholder%3Aoptions%3A%29 Creates a category object containing the specified actions and options. ```swift convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], options: UNNotificationCategoryOptions) ``` -------------------------------- ### Getting the Trigger Information Source: https://developer.apple.com/documentation/usernotifications/uncalendarnotificationtrigger Provides methods to retrieve information about the UNCalendarNotificationTrigger. ```APIDOC ## Getting the Trigger Information ### Description Provides methods to retrieve information about the UNCalendarNotificationTrigger. ### Methods #### `nextTriggerDate()` - **Description**: Returns the next date at which the trigger conditions are met. - **Return Type**: `Date?` #### `dateComponents` - **Description**: Returns the date components used to construct this object. - **Type**: `DateComponents` ``` -------------------------------- ### init(rawValue:) Source: https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextensionresponseoption/init%28rawvalue%3A%29 Initializes a UNNotificationContentExtensionResponseOption instance from a raw UInt value. ```APIDOC ## init(rawValue:) ### Description Creates a new instance of UNNotificationContentExtensionResponseOption from the provided raw integer value. ### Method Initializer ### Parameters #### Request Body - **rawValue** (UInt) - Required - The raw integer value used to initialize the option. ``` -------------------------------- ### Initialize UNNotificationCategory with summary format Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory/init%28identifier%3Aactions%3Aintentidentifiers%3Ahiddenpreviewsbodyplaceholder%3Aoptions%3A%29 Creates a category object containing the specified actions, options, placeholder text, and a summary format string. ```swift convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], hiddenPreviewsBodyPlaceholder: String?, categorySummaryFormat: String?, options: UNNotificationCategoryOptions) ``` -------------------------------- ### Initializers Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory Initializers for creating UNNotificationCategory objects with specified actions, intent identifiers, options, and placeholder text. ```APIDOC ## Initializers ### `convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], options: UNNotificationCategoryOptions)` Creates a category object containing the specified actions and options. ### `convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], hiddenPreviewsBodyPlaceholder: String, options: UNNotificationCategoryOptions)` Creates a category object containing the specified actions, options, and placeholder text used when previews aren’t shown. ### `convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], hiddenPreviewsBodyPlaceholder: String?, categorySummaryFormat: String?, options: UNNotificationCategoryOptions)` Creates a category object containing the specified actions, options, placeholder text used when previews aren’t shown, and summary format string. ``` -------------------------------- ### Getting Trigger Information Source: https://developer.apple.com/documentation/usernotifications/untimeintervalnotificationtrigger Methods and properties to retrieve information about the trigger state. ```APIDOC ## Method: nextTriggerDate() ### Description Returns the next date at which the trigger conditions are met. ### Response - **Date?** - The next date the trigger will fire, or nil if it will not fire again. ## Property: timeInterval ### Description The time interval used to create the trigger. ### Type - **TimeInterval** ``` -------------------------------- ### mediaPlay() Instance Method Source: https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension/mediaplay%28%29 The mediaPlay() method tells the system to begin playback of your media content. It should not be called directly by the developer; the system invokes it when the user interacts with the media playback button. ```APIDOC ## mediaPlay() ### Description Tells you to begin playback of your media content. ### Method `optional func mediaPlay()` ### Availability iOS 10.0+ iPadOS 10.0+ Mac Catalyst 10.0+ macOS 11.0+ visionOS 1.0+ ### Discussion Don’t call this method yourself. If you implement the `mediaPlayPauseButtonFrame` property in your view controller, the system calls this method when the user wants to begin playback of your media. Use your implementation of this method to initiate playback. ### See Also - `var mediaPlayPauseButtonType: UNNotificationContentExtensionMediaPlayPauseButtonType` - `enum UNNotificationContentExtensionMediaPlayPauseButtonType` - `var mediaPlayPauseButtonFrame: CGRect` - `var mediaPlayPauseButtonTintColor: UIColor` - `func mediaPause()` ``` -------------------------------- ### GET UNNotificationTrigger.repeats Source: https://developer.apple.com/documentation/usernotifications/unnotificationtrigger/repeats Retrieves the Boolean value indicating if the notification trigger repeats. ```APIDOC ## GET UNNotificationTrigger.repeats ### Description A Boolean value indicating whether the system reschedules the notification after it’s delivered. ### Method GET ### Endpoint UNNotificationTrigger.repeats ### Response - **repeats** (Bool) - When false, the system delivers the notification only once. When true, the system reschedules the notification request automatically. ``` -------------------------------- ### init(identifier:url:options:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationattachment/init%28identifier%3Aurl%3Aoptions%3A%29-83grx Creates an attachment object from the specified file and options. This initializer is available on iOS 10.0+, iPadOS 10.0+, macOS 10.14+, watchOS 3.0+, and visionOS 1.0+. ```APIDOC ## init(identifier:url:options:) ### Description Creates an attachment object from the specified file and options. ### Method Signature ```swift convenience init( identifier: String, url URL: URL, options: [AnyHashable : Any]? = nil ) throws ``` ### Parameters - **identifier** (String) - 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** (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 Supported File Types. - **options** ([AnyHashable : Any]?) - 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 Also - `UNNotificationAttachmentOptionsTypeHintKey` - `UNNotificationAttachmentOptionsThumbnailHiddenKey` - `UNNotificationAttachmentOptionsThumbnailClippingRectKey` - `UNNotificationAttachmentOptionsThumbnailTimeKey` ``` -------------------------------- ### Initializers Source: https://developer.apple.com/documentation/UserNotifications/UNNotificationCategory Initializers for creating UNNotificationCategory objects. ```APIDOC ## Initializers ### `convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], options: UNNotificationCategoryOptions)` Creates a category object containing the specified actions and options. ### `convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], hiddenPreviewsBodyPlaceholder: String, options: UNNotificationCategoryOptions)` Creates a category object containing the specified actions, options, and placeholder text used when previews aren’t shown. ### `convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], hiddenPreviewsBodyPlaceholder: String?, categorySummaryFormat: String?, options: UNNotificationCategoryOptions)` Creates a category object containing the specified actions, options, placeholder text used when previews aren’t shown, and summary format string. ``` -------------------------------- ### GET notification property Source: https://developer.apple.com/documentation/usernotifications/unnotificationresponse/notification Retrieves the notification object associated with a user response. ```APIDOC ## GET notification ### Description The notification property returns the UNNotification object to which the user responded. ### Method GET ### Endpoint UNNotificationResponse.notification ### Response - **notification** (UNNotification) - The notification to which the user responded. ``` -------------------------------- ### GET UNNotificationRequest.trigger Source: https://developer.apple.com/documentation/usernotifications/unnotificationrequest/trigger Access the trigger property to determine the delivery conditions of a notification. ```APIDOC ## Property: trigger ### Description The conditions that trigger the delivery of the notification. 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. ### Declaration `@NSCopying var trigger: UNNotificationTrigger? { get }` ### Availability - iOS 10.0+ - iPadOS 10.0+ - Mac Catalyst 13.1+ - macOS 10.14+ - tvOS 10.0+ - visionOS 1.0+ - watchOS 3.0+ ``` -------------------------------- ### Initializer: init(rawValue:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationsoundname/init%28rawvalue%3A%29 Creates a notification sound name using the string parameter. Available on iOS 10.0+, iPadOS 10.0+, macOS 10.14+, tvOS 10.0+, visionOS 1.0+, and watchOS 3.0+. ```APIDOC ## init(rawValue:) ### Description Creates a notification sound name using the string parameter. ### Parameters #### Raw Value - **rawValue** (String) - Required - A string containing the name of the sound. ### See Also - `init(String)` ``` -------------------------------- ### UNNotificationCategory Options Property Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory Gets the options that define how notifications of this type are handled. ```swift var options: UNNotificationCategoryOptions ``` -------------------------------- ### Initializer: init(rawValue:) Source: https://developer.apple.com/documentation/usernotifications/unauthorizationoptions/init%28rawvalue%3A%29 Initializes an authorization options constant using the specified raw value. Available on iOS 10.0+, iPadOS 10.0+, macOS 10.14+, tvOS 10.0+, visionOS 1.0+, and watchOS 3.0+. ```APIDOC ## Initializer: init(rawValue:) ### Description Initializes an authorization options constant using the specified raw value. ### Method Initializer ### Endpoint N/A (Initializer) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (N/A) None #### Response Example None ## Parameters `rawValue` The raw unsigned integer value for the authorization options. ``` -------------------------------- ### GET UNNotificationContent.title Source: https://developer.apple.com/documentation/usernotifications/unnotificationcontent/title Access the localized title string of a notification content object. ```APIDOC ## GET UNNotificationContent.title ### Description The localized text that provides the notification’s primary description. When present, the system attempts to display a notification alert if the app is authorized. ### Property Definition `var title: String { get }` ### Usage Notes - Title strings should be short, usually only a couple of words. - On watchOS, the title is displayed as part of the short look notification interface. - If the app is not authorized for alert-based notifications, the system ignores this property. ``` -------------------------------- ### Implement asynchronous userNotificationCenter delegate method Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/usernotificationcenter%28_%3Awillpresent%3Awithcompletionhandler%3A%29 An alternative asynchronous implementation that returns the presentation options directly. ```Swift optional func userNotificationCenter( _ center: UNUserNotificationCenter, willPresent notification: UNNotification ) async -> UNNotificationPresentationOptions ``` ```Swift optional func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions ``` -------------------------------- ### UNNotificationCategory Actions Property Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory Gets the array of UNNotificationAction objects to be displayed for this category. ```swift var actions: [UNNotificationAction] ``` -------------------------------- ### Initializer: init(rawValue:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationpresentationoptions/init%28rawvalue%3A%29 Initializes a notification presentation options object using the specified raw value. Available on iOS 10.0+, iPadOS 10.0+, Mac Catalyst 13.1+, macOS 10.14+, tvOS 10.0+, visionOS 1.0+, watchOS 3.0+. ```APIDOC ## init(rawValue:) ### Description Initializes a notification presentation options object using the specified raw value. ### Method Initializer ### Endpoint N/A (Initializer) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ## Parameters `rawValue` The raw unsigned integer value for the notification presentation options. ``` -------------------------------- ### GET getPendingNotificationRequests Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/getpendingnotificationrequests%28completionhandler%3A%29 Fetches all of the app's local notifications that are currently pending delivery. ```APIDOC ## GET getPendingNotificationRequests(completionHandler:) ### Description Fetches all of your app’s local notifications that are pending delivery. ### Method GET ### Parameters #### Parameters - **completionHandler** (block) - Required - A block for processing notification requests. This block may be executed on a background thread. ### Response #### Success Response (200) - **requests** (Array) - An array of UNNotificationRequest objects representing the scheduled notification requests. If there are no scheduled requests, this array is empty. ``` -------------------------------- ### Get Notification Interruption Level Source: https://developer.apple.com/documentation/usernotifications/unnotificationcontent/interruptionlevel Retrieve the interruption level of a notification. This property is read-only. ```swift var interruptionLevel: UNNotificationInterruptionLevel { get } ``` -------------------------------- ### Sample APNs POST Request with Token Authentication Source: https://developer.apple.com/documentation/usernotifications/sending-notification-requests-to-apns This example demonstrates the structure of a POST request to APNs using token-based authentication. Ensure your headers accurately reflect the notification's target and your authorization credentials. ```http HEADERS - END_STREAM + END_HEADERS :method = POST :scheme = https :path = /3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0 host = api.sandbox.push.apple.com authorization = bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0I jogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6 Lxw7LZtEQcH6JENhJTMArwLf3sXwi apns-id = eabeae54-14a8-11e5-b60b-1697f925ec7b ``` -------------------------------- ### Getting the Response Information Source: https://developer.apple.com/documentation/UserNotifications/UNNotificationResponse Access properties of UNNotificationResponse to understand how the user interacted with a notification. ```APIDOC ## Properties ### `actionIdentifier` The identifier string of the action that the user selected. ### `notification` The notification to which the user responded. ### `targetScene` The scene where the system reflects the user’s response to a notification. ### `UNNotificationDefaultActionIdentifier` An action that indicates the user opened the app from the notification interface. ### `UNNotificationDismissActionIdentifier` The action that indicates the user explicitly dismissed the notification interface. ``` -------------------------------- ### Initializer: init(rawValue:) Source: https://developer.apple.com/documentation/usernotifications/unshowpreviewssetting/init%28rawvalue%3A%29 Initializes a new instance of the User Notifications setting with a raw integer value. This is useful for converting raw data back into a User Notification setting object. ```APIDOC ## init(rawValue:) ### Description Initializes a new instance of the User Notifications setting with a raw integer value. This is useful for converting raw data back into a User Notification setting object. ### Method Initializer ### Endpoint N/A (This is an initializer, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift // Example of creating an initializer with a raw value let rawValue = 1 let notificationSetting = UNShowPreviewsSetting(rawValue: rawValue) ``` ### Response #### Success Response (200) N/A (Initializers do not return HTTP responses) #### Response Example N/A ``` -------------------------------- ### Initialize UNNotificationCategory with hidden preview placeholder Source: https://developer.apple.com/documentation/usernotifications/unnotificationcategory/init%28identifier%3Aactions%3Aintentidentifiers%3Ahiddenpreviewsbodyplaceholder%3Aoptions%3A%29 Creates a category object with specified actions, intent identifiers, and a placeholder string for hidden previews. ```swift convenience init( identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], hiddenPreviewsBodyPlaceholder: String, options: UNNotificationCategoryOptions = [] ) ``` -------------------------------- ### Get Default Notification Sound Source: https://developer.apple.com/documentation/usernotifications/unnotificationsound/defaultringtone Retrieve the system's default notification sound. This property is read-only. ```swift @NSCopying class var defaultRingtone: UNNotificationSound { get } ``` -------------------------------- ### Convert Sound File using afconvert Source: https://developer.apple.com/documentation/usernotifications/unnotificationsound Demonstrates how to use the `afconvert` command-line tool to convert an AIFF sound file to a CAF file with IMA4 audio format. This is useful for preparing custom notification sounds. ```bash afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v ``` -------------------------------- ### Get Scheduled Delivery Setting Source: https://developer.apple.com/documentation/usernotifications/unnotificationsettings/scheduleddeliverysetting Retrieve the setting that indicates the system schedules the notification. This property is read-only. ```swift var scheduledDeliverySetting: UNNotificationSetting { get } ``` -------------------------------- ### Getting the Authorization Status Source: https://developer.apple.com/documentation/usernotifications/unauthorizationstatus This section describes how to retrieve the app's current authorization status for notifications. ```APIDOC ## Property: authorizationStatus ### Description Provides the app’s ability to schedule and receive local and remote notifications. ### Type `var authorizationStatus: UNAuthorizationStatus` ``` -------------------------------- ### Initializer: init(rawValue:) Source: https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextensionmediaplaypausebuttontype/init%28rawvalue%3A%29 This initializer creates a new instance of a notification content extension media play/pause button type from a raw unsigned integer value. It is available on iOS 10.0 and later, iPadOS 10.0 and later, Mac Catalyst 10.0 and later, macOS 11.0 and later, and visionOS 1.0 and later. ```APIDOC ## Initializer: init(rawValue:) ### Description Initializes a new instance of the notification content extension media play/pause button type from its raw value. ### Method `init?(rawValue: UInt)` ### Availability - iOS 10.0+ - iPadOS 10.0+ - Mac Catalyst 10.0+ - macOS 11.0+ - visionOS 1.0+ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Get the next trigger date for UNCalendarNotificationTrigger Source: https://developer.apple.com/documentation/usernotifications/uncalendarnotificationtrigger/nexttriggerdate%28%29 Returns the next date when the notification trigger conditions will be satisfied. ```swift func nextTriggerDate() -> Date? ``` -------------------------------- ### Removing Pending Notifications Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/removependingnotificationrequests%28withidentifiers%3A%29 Example showing how to retrieve the notification center and remove a specific pending request by its identifier. ```swift let center = UNUserNotificationCenter.current() center.removePendingNotificationRequests(withIdentifiers: ["com.example.mynotification"]) ``` -------------------------------- ### init(rawValue:) Source: https://developer.apple.com/documentation/usernotifications/unauthorizationstatus/init%28rawvalue%3A%29 Initializes a UNAuthorizationStatus instance from a raw integer value. ```APIDOC ## init(rawValue:) ### Description Creates a new UNAuthorizationStatus instance from the specified raw integer value. ### Method Initializer ### Parameters #### Request Body - **rawValue** (Int) - Required - The raw integer value representing the authorization status. ``` -------------------------------- ### Fetch pending notifications asynchronously Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/getpendingnotificationrequests%28completionhandler%3A%29 Asynchronous method signature and usage example for retrieving pending notification requests. ```swift func pendingNotificationRequests() async -> [UNNotificationRequest] ``` ```swift let center = UNUserNotificationCenter.current() let requests = await center.pendingNotificationRequests() ``` -------------------------------- ### Implement userNotificationCenter delegate method Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/usernotificationcenter%28_%3Awillpresent%3Awithcompletionhandler%3A%29 The standard synchronous implementation using a completion handler to specify notification presentation options. ```Swift optional func userNotificationCenter( _ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping @Sendable (UNNotificationPresentationOptions) -> Void ) ``` -------------------------------- ### init(coder:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationsettings/init%28coder%3A%29 Initializes a new instance of `UNNotificationSettings` by decoding it from an `NSCoder`. This initializer is typically used during the unarchiving process. ```APIDOC ## init?(coder: NSCoder) ### Description Initializes a new instance of `UNNotificationSettings` by decoding it from an `NSCoder`. This initializer is typically used during the unarchiving process. ### Availability iOS 10.0+ iPadOS 10.0+ Mac Catalyst 13.1+ macOS 10.14+ tvOS 10.0+ visionOS 1.0+ watchOS 3.0+ ### Parameters #### Parameters - **coder** (`NSCoder`) - The coder to decode from. ``` -------------------------------- ### Get Notification Categories (Async) Source: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/getnotificationcategories%28completionhandler%3A%29 This is the asynchronous declaration for fetching notification categories. It returns a set of `UNNotificationCategory` objects. ```swift func notificationCategories() async -> Set ``` -------------------------------- ### Sample POST Request with Token-Based Authentication Source: https://developer.apple.com/documentation/usernotifications/sending-broadcast-push-notification-requests-to-apns This sample demonstrates a POST request to APNs using token-based authentication for a development environment. Ensure all required headers and the JSON payload are correctly formatted. ```http HEADERS - END_STREAM + END_HEADERS :method = POST :scheme = https :path = 4/broadcasts/apps/com.example.MyApp host = api-broadcast.sandbox.push.apple.com authorization = bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0I jogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6 Lxw7LZtEQcH6JENhJTMArwLf3sXwi apns-id = eabeae54-14a8-11e5-b60b-1697f925ec7b apns-push-type = liveactivity apns-expiration = 0 apns-priority = 10 apns-channel-id = dHN0LXNyY2gtY2hubA== DATA + END_STREAM { "aps": { "timestamp": 1685952000, "event": "update", "content-state": { "currentHealthLevel": 0.0, "eventDescription": "Power Panda has been knocked down!" }, "alert": { "title": { "loc-key": "%@ is knocked down!", "loc-args": ["Power Panda"] }, "body": { "loc-key": "Use a potion to heal %@!", "loc-args": ["Power Panda"] }, "sound": "HeroDown.mp4" } } } ``` -------------------------------- ### Get the targetScene Property Source: https://developer.apple.com/documentation/usernotifications/unnotificationresponse/targetscene Access the scene where the system reflects the user's response to a notification. This property is read-only. ```swift var targetScene: UIScene? { get } ``` -------------------------------- ### init(sendMessageIntent:attributedContent:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationattributedmessagecontext/init%28sendmessageintent%3Aattributedcontent%3A%29 Initializes a new message context for a notification using a specific send message intent and attributed string content. ```APIDOC ## init(sendMessageIntent:attributedContent:) ### Description Creates a new UNNotificationAttributedMessageContext instance using the provided INSendMessageIntent and NSAttributedString. ### Method Initializer ### Parameters #### Request Body - **sendMessageIntent** (INSendMessageIntent) - Required - The intent object representing the message to be sent. - **attributedContent** (NSAttributedString) - Required - The attributed string content to be displayed in the notification. ### Request Example convenience init( sendMessageIntent: INSendMessageIntent, attributedContent: NSAttributedString ) ``` -------------------------------- ### didReceive(_:withContentHandler:) Source: https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension/didreceive%28_%3Awithcontenthandler%3A%29 Asks the extension to make any needed changes to the notification and notify the system when finished. ```APIDOC ## didReceive(_:withContentHandler:) ### Description Override this method to modify the UNNotificationContent object that the system delivers with the notification. You must execute the contentHandler block with the modified or original content within 30 seconds. ### Method Instance Method ### Parameters - **request** (UNNotificationRequest) - Required - The original notification request containing the notification content. - **contentHandler** (@escaping (UNNotificationContent) -> Void) - Required - The block to execute with the modified content to deliver to the user. ### Request Example func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { // Modify content here contentHandler(modifiedContent) } ``` -------------------------------- ### GET UNNotificationContent.relevanceScore Source: https://developer.apple.com/documentation/usernotifications/unnotificationcontent/relevancescore Retrieves the relevance score used by the system to determine if a notification is the summary's featured notification. ```APIDOC ## Property: relevanceScore ### Description The score the system uses to determine if the notification is the summary’s featured notification. The system uses this value, between 0 and 1, to sort notifications from your app. ### Declaration `var relevanceScore: Double { get }` ### Availability - iOS 15.0+ - iPadOS 15.0+ - Mac Catalyst 15.0+ - macOS 12.0+ - tvOS 15.0+ - visionOS 1.0+ - watchOS 8.0+ ``` -------------------------------- ### Initializer: init(dateMatching:repeats:) Source: https://developer.apple.com/documentation/usernotifications/uncalendarnotificationtrigger/init%28datematching%3Arepeats%3A%29 Creates a calendar trigger using the date components parameter. This initializer is available on iOS 10.0+, iPadOS 10.0+, Mac Catalyst 13.1+, macOS 10.14+, tvOS 10.0+, visionOS 1.0+, and watchOS 3.0+. ```APIDOC ## Initializer: init(dateMatching:repeats:) ### Description Creates a calendar trigger using the date components parameter. ### Method Convenience Initializer ### Endpoint N/A (Initializer) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift convenience init( dateMatching dateComponents: DateComponents, repeats: Bool ) ``` ### Response #### Success Response (200) N/A (Initializer) #### Response Example N/A (Initializer) ### Parameters - **dateComponents** (DateComponents) - Required - The temporal information to use when constructing the trigger. Provide only the date components that are relevant for your trigger. - **repeats** (Bool) - Required - 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. ``` -------------------------------- ### Get UNNotificationAction Icon Source: https://developer.apple.com/documentation/usernotifications/unnotificationaction The icon property provides access to the UNNotificationActionIcon object associated with the action, if one was set. ```swift var icon: UNNotificationActionIcon? ``` -------------------------------- ### Get UNNotificationAttachment Type Source: https://developer.apple.com/documentation/usernotifications/unnotificationattachment/type Access the UTI type of the notification attachment. This property is read-only and derived from the attachment data. ```swift var type: String { get } ``` -------------------------------- ### Accessing badgeSetting Source: https://developer.apple.com/documentation/usernotifications/unnotificationsettings/badgesetting Retrieves the current authorization status for app icon badging. ```swift var badgeSetting: UNNotificationSetting { get } ``` -------------------------------- ### GET /1/apps//all-channels Source: https://developer.apple.com/documentation/usernotifications/sending-channel-management-requests-to-apns Retrieves a list of all active broadcast channels for a given application bundle ID. ```APIDOC ## GET /1/apps//all-channels ### Description Retrieves the list of all current active channels for your app using a GET request over the APNs connection. ### Method GET ### Endpoint /1/apps//all-channels ### Parameters #### Path Parameters - **bundleId** (string) - Required - The unique bundle identifier for the application. #### Request Headers - **authorization** (string) - Required for token-based auth - Bearer provider_token for authentication. - **apns-request-id** (string) - Optional - A canonical UUID for the request. ### Request Example curl -v -X GET \ -H "authorization: bearer " \ -H "apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127" \ --http2 \ https://api-manage-broadcast.sandbox.push.apple.com:2195/1/apps/com.example.MyApp/all-channels ### Response #### Success Response (200) - **channels** (array) - List of all base64-encoded channel identifiers for the topic. #### Response Example { "channels": ["Y2hhbm5lbDE=", "Y2hhbm5lbDI="] } ``` -------------------------------- ### Show Previews Setting Source: https://developer.apple.com/documentation/usernotifications/unnotificationsettings The setting that indicates whether the app shows a preview of the notification’s content. ```APIDOC ## Show Previews Setting ### Description Indicates whether the app shows a preview of the notification’s content on the Lock screen or in Notification Center. ### Property `var showPreviewsSetting: UNShowPreviewsSetting` ### Type `UNShowPreviewsSetting` (enum) ### Possible Values - `always`: Previews are always shown. - `whenUnlocked`: Previews are shown only when the device is unlocked. - `never`: Previews are never shown. ```