0

I'm trying to get a push notification sent from server when user has my application in background, or closed and the notification came from server. User clicks the push notification bar and the application opens. This works, but I'm not sure how to get the notification object to make it seen and count down badges.

I tried to add observer in my mainviewcontroller

NotificationCenter.default.addObserver(
              self,
              selector: #selector(applicationWillEnterForeground(_:)),
              name: UIApplication.willEnterForegroundNotification,
              object: nil)

I tried to add code to my AppDelegate

func applicationWillEnterForeground(_ application: UIApplication) {
        print(">>>>applicationWillEnterForeground;AppDelegate")
    }

This two blocks are responding, but I'm not sure how to access clicked notification object

I have tried

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

But after the push notification click, application is opening a webpage in safari, so no processing is happening in this method

Marcel Kopera
  • 91
  • 1
  • 7
  • Have you looked at the `UIApplicationDelegate application(_:didReceiveRemoteNotification:fetchCompletionHandler:)` method? – HangarRash Nov 14 '22 at 00:31
  • Does this answer your question? [Detect if the app was launched/opened from a push notification](https://stackoverflow.com/questions/16393673/detect-if-the-app-was-launched-opened-from-a-push-notification) – HangarRash Nov 14 '22 at 00:34
  • tried both, no response, no print statement executed from there ... my app is opening webview after the notification touch, maybe this is the reason? – Marcel Kopera Nov 14 '22 at 00:42
  • As a test, don't launch Safari when you get the notification. Does the `didReceiveRemoteNotification` delegate method get called now? – HangarRash Nov 14 '22 at 01:23
  • Safari launch is executed from SDK file of the Notification package, I'm not able to touch it – Marcel Kopera Nov 14 '22 at 01:27

0 Answers0