UNUserNotificationCenter function is not called when the button is pressed Action Chat in the notice after the 3D-touch, if the application is inactive (not even in the background, or has not been completed). I used the "attach to process by name" in Xcode to debug the application, when an application has been terminated. Here is the code:
import UIKit import Mixpanel import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
When a notification pop-up message (sent from MixPanel), this function is called first,
Call 1:
func handlePushNotificationWithUserInfo(launchOptions: [NSObject: AnyObject]?) { //Handle PushNotification when app is opened }
Then he goes here
Call 2:
//register for notification func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { if didRegister notificationSettings: UIUserNotificationSettings) { //register for notification func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { if ]) {(granted, error) in //register for notification func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { if , title: "Chat", options: [.foreground]) //register for notification func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { if
Call 3:
But below the function is not called. But if the application is running in the background, the following function is called and is operating normally. OTHERWISE App comes to the fore and not after that chat.
// action buttons in enhanced Notification @available(iOS 10, *) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> 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) -> Void) { completionHandler([.alert, .sound]) } } response.actionIdentifier) else { // action buttons in enhanced Notification @available(iOS 10, *) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> 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) -> Void) { completionHandler([.alert, .sound]) } } "chat") as URL?) // action buttons in enhanced Notification @available(iOS 10, *) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> 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) -> Void) { completionHandler([.alert, .sound]) } } ) // action buttons in enhanced Notification @available(iOS 10, *) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> 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) -> Void) { completionHandler([.alert, .sound]) } }
This function is never called because it depreciated in iOS 10 through userNotificationCenter (), but not sure. Please explain this as well.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { ....Some Code.... }
I use the iPhone 6s iOS 10 as a debugging device. 8 XCode beta-3