UNUserNotificationCenter didRecieve Response is not called if App is terminated
<p>UNUserNotificationCenter function is not called on clicking <strong>Action Button</strong> Chat in Notification after 3D Touch if App is not active(not even in Background or say has terminated). I used "attach to process by name" in Xcode to debug app when app was terminated. Here is the Code:</p>

<pre><code>import UIKit
import Mixpanel
import UserNotifications

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
        //setup mixpanel

        self.handlePushNotificationWithUserInfo(launchOptions: launchOptions)

        //ask for push notification perms
        return true
    }
</code></pre>

<p>When Notification Pop-up (Sent from MixPanel) this function is called first,</p>

<p>Call 1:</p>

<pre><code>    func handlePushNotificationWithUserInfo(launchOptions: [NSObject: AnyObject]?) {
        //Handle PushNotification when app is opened
    }
</code></pre>

<p>Then It goes here,</p>

<p>Call 2:</p>

<pre><code>    //register for notification
    func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {

        if #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.current()
            center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
                // Enable or disable features based on authorization.
            }
            center.delegate = self

            let actionChat = UNNotificationAction(identifier: Constants.ActionType.CHAT.rawValue, title: "Chat", options: [.foreground])
            let categoryOptions = UNNotificationCategoryOptions(rawValue: 0)
            let customerSupportCategory = UNNotificationCategory(identifier: Constants.NotificationType.CUSTOMER_SUPPORT.rawValue, actions: [actionChat], intentIdentifiers: [], options: categoryOptions)
            center.setNotificationCategories([customerSupportCategory])
        }

        application.registerForRemoteNotifications()
    }
</code></pre>

<p>Call 3:    </p>

<pre><code>    // remote notification
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        ....Some Code....
    }
</code></pre>

<p>But <strong>below function is not called</strong>.
But if <strong>app is running in background</strong> then below function is called and <strong>all works fine OTHERWISE App comes to foreground and chat does not after that</strong>.</p>

<pre><code>    // action buttons in enhanced Notification
    @available(iOS 10, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -&gt; Void) {
        guard let action = Constants.ActionType(rawValue: response.actionIdentifier) else {
            completionHandler()
            return
        }
        switch action {
        case .CHAT:
            _ = self.handleRemoteUrl(NSURL(string: "chat") as? URL)
        default:
            _ = self.handleRemoteUrl(NSURL(string: "chat") as? URL)
        }
        completionHandler()
    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -&gt; Void) {
        completionHandler([.alert, .sound])
    }
}
</code></pre>

<p>This function is never called may be because it's depreciated in iOS 10 over userNotificationCenter(), not sure. Please explain this also..</p>

<pre><code>    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        ....Some Code....
    }
</code></pre>

<p><strong>I am using iPhone 6s iOS 10 as debugging device.</strong>
<strong>XCode 8 beta-3</strong></p>