Add custom local notification in ios10 - swift 3

I am trying to add a custom local notification, but I only get a stock notification with my action:

enter image description here

My storyboard looks like this (standard template):

enter image description here

I have an extension for which UNNotificationExtensionCategory set to awesomeNotification (in Info.plist). Also, the basis of this extension is the Notification Content template from iOS - Application Extension .

In my application, I have the following:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let center = UNUserNotificationCenter.current() let actions = [UNNotificationAction.init(identifier: "Hey", title: "Yo", options: UNNotificationActionOptions.foreground)] let category = UNNotificationCategory(identifier: "awesomeNotification", actions: actions, minimalActions: actions, intentIdentifiers: [], options: []) center.setNotificationCategories([category]) center.requestAuthorization([.alert, .sound]) { (granted, error) in } return true } 

In my view manager in the main application, I have the following action to launch it:

 @IBAction func sendPressed(_ sender: AnyObject) { let content = UNMutableNotificationContent() content.categoryIdentifier = "awesomeNotification" content.title = "Hello" content.body = "What up?" 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) in print(error) } print("should have been added") } 

Edit

So it works on the iPhone 6s / 6s +, a very strange behavior: enter image description here

+7
ios10 swift swift3 uilocalnotification unusernotificationcenter
source share
1 answer

Update. Starting with iOS 10 beta 2, devices with advanced 3D touch also have rich notifications. Release the regular notification to see it.

Make sure you're testing on iPhone6s / iPhone6s plus a simulator / device, it doesn't seem to work on devices with 3D preliminary touch.

On the iPhone6 ​​simulator, try clicking and dragging the stock notification you get and you will see how the user interface appears.

+5
source share

All Articles