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!