Implementation

suggest change
  1. In the Xcode navigator, select the project, open the target list, and click Add New Target.
  2. Select the Notification Content Extension template:

  1. In the extension’s Info.plist, set UNNotificationExtensionCategory:

NSExtensionAttributes:

UNNotificationExtensionCategory (Required)

The value of this key is a string or an array of strings. Each string is the identifier of a category the app declares with UNNotificationCategory.

UNNotificationExtensionInitialContentSizeRatio (Required)

Number that represents the initial size of your view controller’s view expressed as a ratio of its height to its width.

UNNotificationExtensionDefaultContentHidden (Optional)

When set to YES, the system displays only your custom view controller in the notification interface. When set to NO, the system displays the default notification content in addition to your view controller’s content.

UNNotificationExtensionOverridesDefaultTitle (Optional)

The value of this key is a Boolean. When set to true, the system uses the title property of your view controller as the title of the notification. When set to false, the system sets the notification’s title to the name of your app. If you do not specify this key, the default value is set to false.

  1. Create the custom view in NotificationViewController.swift.
  2. Give the notification the same category identifier as step 3. The property is categoryIdentifier, not category. The push sketch below is JSON. The original left the keys unquoted.

Push:

{
  "aps": {
    "alert": {},
    "category": "io.swifting.notification-category"
  }
}

Local:

let mutableNotificationContent = UNMutableNotificationContent()
mutableNotificationContent.categoryIdentifier = "io.swifting.notification-category"
mutableNotificationContent.title = "Swifting.io Notifications"
mutableNotificationContent.subtitle = "Swifting.io presents"
mutableNotificationContent.body = "Custom notifications"

Also check out the official API reference: https://developer.apple.com/reference/usernotificationsui/unnotificationcontentextension?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents