2
votes

userNotificationCenter(...,didReceive,...) and userNotificationCenter(...,willPresent,...) are used respectively to:

  • handle when the user taps on a notification while the app is in the background

  • handle when the phone receives a notification while the app is in the foreground.

But how do we handle the event in which the user taps on the notification while the app is in the foreground? (to, for instance, take the user to the relevant view controller when tapping on the notification)

1

1 Answers

1
votes

There are two didReceive methods, and they act differently. As it says on the page for the didReceiveRemoteNotification:fetchCompletionHandler:

"Unlike the application(_:didReceiveRemoteNotification:) method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background."