Why userNotificationCenter didReceive is not fired?












0















This is a part of my code. I want to use UNUserNotificationCenter and UNUserNotificationCenterDelegate to handle notification events.



This code catches the notification event when the app is in a foreground state. But "didReceive" is not fired for a background state.



func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
UNUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()
return true
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
print("willPresent") /// This works
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
print("didReceive") /// This doesn't work
completionHandler()
}


But if I don't use UNUserNotificationCenter.current().delegate = self the delegate method is correctly fired in the background.



func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping FetchCompletionHandler) {
print("didReceiveRemoteNotification... (userInfo)")
}


How can I use "didReceive"? I want to handle the notification in the background.










share|improve this question





























    0















    This is a part of my code. I want to use UNUserNotificationCenter and UNUserNotificationCenterDelegate to handle notification events.



    This code catches the notification event when the app is in a foreground state. But "didReceive" is not fired for a background state.



    func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:
    [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    UNUserNotificationCenter.current().delegate = self
    application.registerForRemoteNotifications()
    return true
    }
    func userNotificationCenter(_ center: UNUserNotificationCenter,
    willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
    {
    print("willPresent") /// This works
    completionHandler([.alert, .badge, .sound])
    }
    func userNotificationCenter(_ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void) {
    print("didReceive") /// This doesn't work
    completionHandler()
    }


    But if I don't use UNUserNotificationCenter.current().delegate = self the delegate method is correctly fired in the background.



    func application(_ application: UIApplication,
    didReceiveRemoteNotification userInfo: [AnyHashable: Any],
    fetchCompletionHandler completionHandler: @escaping FetchCompletionHandler) {
    print("didReceiveRemoteNotification... (userInfo)")
    }


    How can I use "didReceive"? I want to handle the notification in the background.










    share|improve this question



























      0












      0








      0








      This is a part of my code. I want to use UNUserNotificationCenter and UNUserNotificationCenterDelegate to handle notification events.



      This code catches the notification event when the app is in a foreground state. But "didReceive" is not fired for a background state.



      func application(_ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions:
      [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
      UNUserNotificationCenter.current().delegate = self
      application.registerForRemoteNotifications()
      return true
      }
      func userNotificationCenter(_ center: UNUserNotificationCenter,
      willPresent notification: UNNotification,
      withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
      {
      print("willPresent") /// This works
      completionHandler([.alert, .badge, .sound])
      }
      func userNotificationCenter(_ center: UNUserNotificationCenter,
      didReceive response: UNNotificationResponse,
      withCompletionHandler completionHandler: @escaping () -> Void) {
      print("didReceive") /// This doesn't work
      completionHandler()
      }


      But if I don't use UNUserNotificationCenter.current().delegate = self the delegate method is correctly fired in the background.



      func application(_ application: UIApplication,
      didReceiveRemoteNotification userInfo: [AnyHashable: Any],
      fetchCompletionHandler completionHandler: @escaping FetchCompletionHandler) {
      print("didReceiveRemoteNotification... (userInfo)")
      }


      How can I use "didReceive"? I want to handle the notification in the background.










      share|improve this question
















      This is a part of my code. I want to use UNUserNotificationCenter and UNUserNotificationCenterDelegate to handle notification events.



      This code catches the notification event when the app is in a foreground state. But "didReceive" is not fired for a background state.



      func application(_ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions:
      [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
      UNUserNotificationCenter.current().delegate = self
      application.registerForRemoteNotifications()
      return true
      }
      func userNotificationCenter(_ center: UNUserNotificationCenter,
      willPresent notification: UNNotification,
      withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
      {
      print("willPresent") /// This works
      completionHandler([.alert, .badge, .sound])
      }
      func userNotificationCenter(_ center: UNUserNotificationCenter,
      didReceive response: UNNotificationResponse,
      withCompletionHandler completionHandler: @escaping () -> Void) {
      print("didReceive") /// This doesn't work
      completionHandler()
      }


      But if I don't use UNUserNotificationCenter.current().delegate = self the delegate method is correctly fired in the background.



      func application(_ application: UIApplication,
      didReceiveRemoteNotification userInfo: [AnyHashable: Any],
      fetchCompletionHandler completionHandler: @escaping FetchCompletionHandler) {
      print("didReceiveRemoteNotification... (userInfo)")
      }


      How can I use "didReceive"? I want to handle the notification in the background.







      ios swift push-notification unusernotificationcenter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 16:48









      JJJ

      29.2k147591




      29.2k147591










      asked Nov 24 '18 at 16:44









      VyacheslavVyacheslav

      14.3k962123




      14.3k962123
























          3 Answers
          3






          active

          oldest

          votes


















          1














          application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is called when the application receives a silent push notification. Silent push notifications can be delivered in when the application is in the background state, iOS wakes the application to perform background processing invisible to the user.



          A silent push notification has the content-available flag set to 1.



          Silent push notifications should not include an alert, badge, or sound. Silent push is not meant to be visible to the user, it is only a hint to the application that new remote content is available.



          Removing the content-available flag from your push notification payload will cause iOS to handle it as a regular notification. The user notification center delegate methods will be called instead of application(_:didReceiveRemoteNotification:fetchCompletionHandler:) but your application will be unable to do background processing triggered by the notification.



          You can validate the content of your push notification payload for problems like this using this tool






          share|improve this answer































            0














            This is how I handle push notification in my app. I think you need to implement all of these methods to handle all iOS versions in the foreground and background mode.



            func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

            if #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.current()
            center.delegate = self
            center.requestAuthorization(options: [.sound,.alert,.badge], completionHandler: { (granted, error) in
            if error == nil {
            DispatchQueue.main.async {
            application.registerForRemoteNotifications()
            }
            }
            })
            }
            else {
            let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
            let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
            application.registerUserNotificationSettings(pushNotificationSettings)
            application.registerForRemoteNotifications()
            }

            }

            func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
            let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
            print(deviceTokenString)
            }

            func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
            print("Failed to get token; error: (error)")
            }

            @available(iOS 10.0, *)
            func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            completionHandler([.alert,.sound])
            //do sth
            }

            @available(iOS 10.0, *)
            func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            //do sth
            }

            // for iOS < 10
            func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
            }

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





            share|improve this answer































              -1














              There are methods of UNUserNotificationCenterDelegate:




              • willPresent: This method gets called when you receive a notification when your app is in the foreground. If the app is in the background then this method will not calls.


              • didRecieve: This method gets called when a user clicked on the notification.



              In case of background state, only 'didRecieve' will be called when user will click on a notification.






              share|improve this answer
























              • Why downvote my answer, please explain?

                – iDev750
                Nov 27 '18 at 5:58











              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460280%2fwhy-usernotificationcenter-didreceive-is-not-fired%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is called when the application receives a silent push notification. Silent push notifications can be delivered in when the application is in the background state, iOS wakes the application to perform background processing invisible to the user.



              A silent push notification has the content-available flag set to 1.



              Silent push notifications should not include an alert, badge, or sound. Silent push is not meant to be visible to the user, it is only a hint to the application that new remote content is available.



              Removing the content-available flag from your push notification payload will cause iOS to handle it as a regular notification. The user notification center delegate methods will be called instead of application(_:didReceiveRemoteNotification:fetchCompletionHandler:) but your application will be unable to do background processing triggered by the notification.



              You can validate the content of your push notification payload for problems like this using this tool






              share|improve this answer




























                1














                application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is called when the application receives a silent push notification. Silent push notifications can be delivered in when the application is in the background state, iOS wakes the application to perform background processing invisible to the user.



                A silent push notification has the content-available flag set to 1.



                Silent push notifications should not include an alert, badge, or sound. Silent push is not meant to be visible to the user, it is only a hint to the application that new remote content is available.



                Removing the content-available flag from your push notification payload will cause iOS to handle it as a regular notification. The user notification center delegate methods will be called instead of application(_:didReceiveRemoteNotification:fetchCompletionHandler:) but your application will be unable to do background processing triggered by the notification.



                You can validate the content of your push notification payload for problems like this using this tool






                share|improve this answer


























                  1












                  1








                  1







                  application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is called when the application receives a silent push notification. Silent push notifications can be delivered in when the application is in the background state, iOS wakes the application to perform background processing invisible to the user.



                  A silent push notification has the content-available flag set to 1.



                  Silent push notifications should not include an alert, badge, or sound. Silent push is not meant to be visible to the user, it is only a hint to the application that new remote content is available.



                  Removing the content-available flag from your push notification payload will cause iOS to handle it as a regular notification. The user notification center delegate methods will be called instead of application(_:didReceiveRemoteNotification:fetchCompletionHandler:) but your application will be unable to do background processing triggered by the notification.



                  You can validate the content of your push notification payload for problems like this using this tool






                  share|improve this answer













                  application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is called when the application receives a silent push notification. Silent push notifications can be delivered in when the application is in the background state, iOS wakes the application to perform background processing invisible to the user.



                  A silent push notification has the content-available flag set to 1.



                  Silent push notifications should not include an alert, badge, or sound. Silent push is not meant to be visible to the user, it is only a hint to the application that new remote content is available.



                  Removing the content-available flag from your push notification payload will cause iOS to handle it as a regular notification. The user notification center delegate methods will be called instead of application(_:didReceiveRemoteNotification:fetchCompletionHandler:) but your application will be unable to do background processing triggered by the notification.



                  You can validate the content of your push notification payload for problems like this using this tool







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 27 '18 at 5:58









                  quellishquellish

                  19k45470




                  19k45470

























                      0














                      This is how I handle push notification in my app. I think you need to implement all of these methods to handle all iOS versions in the foreground and background mode.



                      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

                      if #available(iOS 10.0, *) {
                      let center = UNUserNotificationCenter.current()
                      center.delegate = self
                      center.requestAuthorization(options: [.sound,.alert,.badge], completionHandler: { (granted, error) in
                      if error == nil {
                      DispatchQueue.main.async {
                      application.registerForRemoteNotifications()
                      }
                      }
                      })
                      }
                      else {
                      let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
                      let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
                      application.registerUserNotificationSettings(pushNotificationSettings)
                      application.registerForRemoteNotifications()
                      }

                      }

                      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
                      let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
                      print(deviceTokenString)
                      }

                      func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
                      print("Failed to get token; error: (error)")
                      }

                      @available(iOS 10.0, *)
                      func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
                      completionHandler([.alert,.sound])
                      //do sth
                      }

                      @available(iOS 10.0, *)
                      func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
                      //do sth
                      }

                      // for iOS < 10
                      func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
                      }

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





                      share|improve this answer




























                        0














                        This is how I handle push notification in my app. I think you need to implement all of these methods to handle all iOS versions in the foreground and background mode.



                        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

                        if #available(iOS 10.0, *) {
                        let center = UNUserNotificationCenter.current()
                        center.delegate = self
                        center.requestAuthorization(options: [.sound,.alert,.badge], completionHandler: { (granted, error) in
                        if error == nil {
                        DispatchQueue.main.async {
                        application.registerForRemoteNotifications()
                        }
                        }
                        })
                        }
                        else {
                        let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
                        let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
                        application.registerUserNotificationSettings(pushNotificationSettings)
                        application.registerForRemoteNotifications()
                        }

                        }

                        func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
                        let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
                        print(deviceTokenString)
                        }

                        func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
                        print("Failed to get token; error: (error)")
                        }

                        @available(iOS 10.0, *)
                        func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
                        completionHandler([.alert,.sound])
                        //do sth
                        }

                        @available(iOS 10.0, *)
                        func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
                        //do sth
                        }

                        // for iOS < 10
                        func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
                        }

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





                        share|improve this answer


























                          0












                          0








                          0







                          This is how I handle push notification in my app. I think you need to implement all of these methods to handle all iOS versions in the foreground and background mode.



                          func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

                          if #available(iOS 10.0, *) {
                          let center = UNUserNotificationCenter.current()
                          center.delegate = self
                          center.requestAuthorization(options: [.sound,.alert,.badge], completionHandler: { (granted, error) in
                          if error == nil {
                          DispatchQueue.main.async {
                          application.registerForRemoteNotifications()
                          }
                          }
                          })
                          }
                          else {
                          let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
                          let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
                          application.registerUserNotificationSettings(pushNotificationSettings)
                          application.registerForRemoteNotifications()
                          }

                          }

                          func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
                          let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
                          print(deviceTokenString)
                          }

                          func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
                          print("Failed to get token; error: (error)")
                          }

                          @available(iOS 10.0, *)
                          func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
                          completionHandler([.alert,.sound])
                          //do sth
                          }

                          @available(iOS 10.0, *)
                          func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
                          //do sth
                          }

                          // for iOS < 10
                          func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
                          }

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





                          share|improve this answer













                          This is how I handle push notification in my app. I think you need to implement all of these methods to handle all iOS versions in the foreground and background mode.



                          func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

                          if #available(iOS 10.0, *) {
                          let center = UNUserNotificationCenter.current()
                          center.delegate = self
                          center.requestAuthorization(options: [.sound,.alert,.badge], completionHandler: { (granted, error) in
                          if error == nil {
                          DispatchQueue.main.async {
                          application.registerForRemoteNotifications()
                          }
                          }
                          })
                          }
                          else {
                          let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
                          let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
                          application.registerUserNotificationSettings(pushNotificationSettings)
                          application.registerForRemoteNotifications()
                          }

                          }

                          func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
                          let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
                          print(deviceTokenString)
                          }

                          func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
                          print("Failed to get token; error: (error)")
                          }

                          @available(iOS 10.0, *)
                          func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
                          completionHandler([.alert,.sound])
                          //do sth
                          }

                          @available(iOS 10.0, *)
                          func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
                          //do sth
                          }

                          // for iOS < 10
                          func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
                          }

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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 24 '18 at 18:00









                          Hasti RanjkeshHasti Ranjkesh

                          242112




                          242112























                              -1














                              There are methods of UNUserNotificationCenterDelegate:




                              • willPresent: This method gets called when you receive a notification when your app is in the foreground. If the app is in the background then this method will not calls.


                              • didRecieve: This method gets called when a user clicked on the notification.



                              In case of background state, only 'didRecieve' will be called when user will click on a notification.






                              share|improve this answer
























                              • Why downvote my answer, please explain?

                                – iDev750
                                Nov 27 '18 at 5:58
















                              -1














                              There are methods of UNUserNotificationCenterDelegate:




                              • willPresent: This method gets called when you receive a notification when your app is in the foreground. If the app is in the background then this method will not calls.


                              • didRecieve: This method gets called when a user clicked on the notification.



                              In case of background state, only 'didRecieve' will be called when user will click on a notification.






                              share|improve this answer
























                              • Why downvote my answer, please explain?

                                – iDev750
                                Nov 27 '18 at 5:58














                              -1












                              -1








                              -1







                              There are methods of UNUserNotificationCenterDelegate:




                              • willPresent: This method gets called when you receive a notification when your app is in the foreground. If the app is in the background then this method will not calls.


                              • didRecieve: This method gets called when a user clicked on the notification.



                              In case of background state, only 'didRecieve' will be called when user will click on a notification.






                              share|improve this answer













                              There are methods of UNUserNotificationCenterDelegate:




                              • willPresent: This method gets called when you receive a notification when your app is in the foreground. If the app is in the background then this method will not calls.


                              • didRecieve: This method gets called when a user clicked on the notification.



                              In case of background state, only 'didRecieve' will be called when user will click on a notification.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 24 '18 at 17:50









                              iDev750iDev750

                              5961316




                              5961316













                              • Why downvote my answer, please explain?

                                – iDev750
                                Nov 27 '18 at 5:58



















                              • Why downvote my answer, please explain?

                                – iDev750
                                Nov 27 '18 at 5:58

















                              Why downvote my answer, please explain?

                              – iDev750
                              Nov 27 '18 at 5:58





                              Why downvote my answer, please explain?

                              – iDev750
                              Nov 27 '18 at 5:58


















                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460280%2fwhy-usernotificationcenter-didreceive-is-not-fired%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              404 Error Contact Form 7 ajax form submitting

                              How to know if a Active Directory user can login interactively

                              TypeError: fit_transform() missing 1 required positional argument: 'X'