【问题标题】:Detect when user taps on a notification while app is in foreground当应用程序在前台时检测用户何时点击通知
【发布时间】:2017-12-04 16:06:50
【问题描述】:

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

  • 当应用在后台

  • 时用户点击通知时处理
  • 当应用在前台时手机收到通知时处理。

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

【问题讨论】:

    标签: ios swift push-notification apple-push-notifications


    【解决方案1】:

    有两种 didReceive 方法,它们的作用不同。 正如the page for the didReceiveRemoteNotification:fetchCompletionHandler 所说:

    “与application(_:didReceiveRemoteNotification:)方法不同,该方法仅在您的应用程序运行在前台时调用,系统会在您的应用程序在前台或后台运行时调用此方法。”

    【讨论】:

    • 我没有意识到当你点击通知时userNotificationCenter(...,didReceive,...)仍然被调用,即使userNotificationCenter(...,willPresent,...)刚刚被调用,因为应用程序在前台。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2023-03-19
    • 2023-03-11
    • 2015-11-10
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 2018-11-08
    相关资源
    最近更新 更多