I am trying to implement app launch (from inactive state) with an action from a local notification in iOS 10.
I have followed Launch a local notification at a specific time in iOS and the app launches fine in response to the local notification. But what I want from here is to perform an action in response to data in the notification.
In iOS 8 and 9 I had the setup in AppDelegate
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
if (application.applicationState == UIApplicationState.inactive || application.applicationState == UIApplicationState.background) {
NotificationCenter.default.post(name: Notification.Name(rawValue: "noteName", object: notification.alertBody)
and the observer catching it in ViewController
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.txtFromNotifier), name: NSNotification.Name(rawValue: "noteName", object: nil)
and in iOS 10 now in AppDelegate:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// Determine the user action
switch response.actionIdentifier {
case UNNotificationDismissActionIdentifier:
print("Dismiss Action")
case UNNotificationDefaultActionIdentifier:
print("Default")
// do something here
I haven't been able to find how to get from the UNNotification Default action ("Default" gets printed in the console after launch) to passing the parameters and executing the txtFromNotifier function in ViewController. Trying to use the NotificationCenter post / addObserver combination works when the app is in the background but doesn't get there when the app is inactive.
Any ideas?