Notification Content Extension failing to run on Mac

Hi,

I'm trying to use UNNotificationContentExtension for a SwiftUI Mac application, and I'm unable to get it to run - the default notification type is displayed instead.

I'm using Mac OS 12.6.7 and Xcode 14.2

To reproduce, create a new SwiftUI Mac application, and replace the contents of the ContentView body VStack with the following:

Button("Request Permission") {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
        if success {
            print("All set!")
        } else if let error = error {
            print(error.localizedDescription)
        }
    }
    let notificationCategory = UNNotificationCategory(identifier: "test", actions: [], intentIdentifiers: [])
    UNUserNotificationCenter.current().setNotificationCategories([notificationCategory])
}

Button("Schedule Notification") {
    let content = UNMutableNotificationContent()
    content.title = "Testing"
    content.categoryIdentifier = "test"
    content.sound = UNNotificationSound.default

    // show this notification five seconds from now
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)

    // choose a random identifier
    let request = UNNotificationRequest(identifier: "myApp", content: content, trigger: trigger)

    // add our notification request
    UNUserNotificationCenter.current().add(request)
}

Then do New->Target->Notification Content Extension.

In the extension Info.plist, set UNNotificationExtensionCategory to 'test'.

My understanding was that this should be enough to get the extension to load, but it doesn't seem to be. Am I missing something?

Thanks in advance!

I missed a couple of steps above. You'll need to import UserNotifications in your ContentView.swift, and you'll also need to enable notifications as alerts for the test app. I guess one question is whether it's supported at all? It builds and runs fine, and is listed as supported in the documentation:

https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension

But then this page says "Notification content app extensions are supported only in iOS apps."

https://developer.apple.com/documentation/usernotificationsui/customizing_the_appearance_of_notifications

Notification Content Extension failing to run on Mac
 
 
Q