检测用户何时在应用程序处于前台时点击通知

Detect when user taps on a notification while app is in foreground

userNotificationCenter(...,didReceive,...)userNotificationCenter(...,willPresent,...)分别用于:

但是当应用程序处于前台时,我们如何处理用户点击通知的事件? (例如,在点击通知时将用户带到相关的视图控制器)

有两种 didReceive 方法,它们的作用不同。 正如它在 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."