I'm trying to use the new UNNotificationContentExtension to display a custom user interface for local notifications but only the default notification alert is shown.
I created the extension with the Xcode template and specified the UNNotificationExtensionCategory
in the Info.plist.
After this I'm registering for notifications and setting up the UNNotificationCategory
in application(_:didFinishLaunchingWithOptions:)
let center = UNUserNotificationCenter.current()
center.requestAuthorization([.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
let action = UNNotificationAction(identifier: "Delete", title: "Delete", options: [])
let category = UNNotificationCategory(identifier: "notify-test", actions: [action], minimalActions: [], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
I'm scheduling the notification to trigger five seconds after the App did enter the background with this code:
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()
content.categoryIdentifier = "notify-test"
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
let request = UNNotificationRequest.init(identifier: "notify-test", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request)
The notification fires as expected but on the iOS default style is shown, none of the custom UI defined in the default Storyboard file is shown. Maybe someone ran into the same problem before and can help me here.