2

I can't find any documentation on how to handle this, I'm sending a push notification using firebase messaging with a data payload, title and message. The notification comes through fine but opening the app from background does't trigger any specific options here:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {        FirebaseApp.configure();
    // Override point for customization after application launch.
    return true
}

The function doesn't seem to be called.

meds
  • 21,699
  • 37
  • 163
  • 314
  • 1
    Have you tried any of this? https://stackoverflow.com/questions/16393673/detect-if-the-app-was-launched-opened-from-a-push-notification – Pastre Oct 22 '22 at 22:04

1 Answers1

1

This is the function called for push notification presses

func userNotificationCenter(_ center: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo

    let application = UIApplication.shared
     
     if(application.applicationState == .active){
       //Prints the message when user tapped the notification bar when the app is in foreground
       print(userInfo)
     }
     
     if(application.applicationState == .inactive)
     {
       print("user tapped the notification bar when the app is in background")
     }

    completionHandler()
  }
teja_D
  • 383
  • 3
  • 18