1

I made a lot of search during many days (20 posts+) but I didn't the solution to my problem.

I have an application which receive push notification, I can receive those remote notifications but when I tap on it, the delegate "didReceiveRemoteNotification" is not called (I want to intercept the payload to do action in fonction of it).

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print("test")
}

In advance, thanks for help.

The didReceiveRemoteNotification method does not fire when the user launches the app by tapping on the notification and not when the notification is received, never.

Sorry for my bad english and if you have question, don't hesitate.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Nuccle
  • 23
  • 1
  • 7
  • Possible duplicate of [didReceiveRemoteNotification not called , iOS 10](http://stackoverflow.com/questions/39382852/didreceiveremotenotification-not-called-ios-10) – LC 웃 May 02 '17 at 07:50
  • I have already tried the solutions on this post – Nuccle May 02 '17 at 08:08
  • If you want to handle the notification when it's delivered to the user? Use the UNUserNotificationCenterDelegate protocol methods – Mannopson May 02 '17 at 08:36
  • @Mannopson , I just added : @ available(iOS 10.0, *) func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @ escaping (UNNotificationPresentationOptions) -> Void) { print("test2") } @ available(iOS 10.0, *) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @ escaping () -> Void) { print("test3") } But nothing is called – Nuccle May 02 '17 at 09:04
  • Set the delegate to self and then works. – Mannopson May 02 '17 at 09:05
  • See this answer: http://stackoverflow.com/a/43647816/6680583 – Mannopson May 02 '17 at 09:06
  • @Mannopson I've already this code : //create the notificationCenter if #available(iOS 10.0, *) { let center = UNUserNotificationCenter.current() center.delegate = self // set the type as sound or badge center.requestAuthorization(options: [.sound,.alert,.badge]) { (granted, error) in // Enable or disable features based on authorization } application.registerForRemoteNotifications() } else { // Fallback on earlier versions } – Nuccle May 02 '17 at 09:09
  • Check the comment above – Mannopson May 02 '17 at 09:10
  • @Mannopson is your answer is for remote notification ? Because i think it's for LOCAL notification – Nuccle May 02 '17 at 09:17
  • It's works with the remote and local notifications – Mannopson May 02 '17 at 09:20
  • https://forums.developer.apple.com/thread/54332 – Jigar Tarsariya May 02 '17 at 09:37
  • 1
    Mannopson I tried your solution but willPresent and didReceive delegates still not called @JigarTarsariya I saw this solution but can't test it because it was in Obj C, how can i do the same in Swift 3 please ? – Nuccle May 02 '17 at 09:41
  • @Nuccle This is not my solution:) It's an API and it's provided by Apple – Mannopson May 02 '17 at 12:10
  • @Nuccle.. Did u find any solution . I am still not getting notifications – Uma Madhavi Jun 08 '17 at 12:15
  • @UmaMadhavi Yes problem solved, I had this line "UNUserNotificationCenter.current().delegate = self" in my first viewController, it created a conflict with the UNUserNotificationCenter which I declared in my appDelegate – Nuccle Jun 12 '17 at 11:19

1 Answers1

-2

First import UserNotification framework and then implement UNUserNotificationCenterDelegate in ios10 to support push notification in ios10

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
          //Handle notification tap
  }
Dhruv
  • 72
  • 4