【问题标题】:Notify application when a notification has been received and not tapped on or dismissed在收到通知但未点击或关闭通知时通知应用程序
【发布时间】:2026-02-11 17:05:02
【问题描述】:

在 iOS 10 上,是否有任何代理通知应用程序通知未被点击或被取消?

我的意思是,即使用户没有点击,如何获取通知数据?

我有这两个委托方法,它们仅在用户点击通知时响应:

func userNotificationCenter(_ center: UNUserNotificationCenter,  willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (_ options:   UNNotificationPresentationOptions) -> Void) {}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {}

【问题讨论】:

  • 将数据保存在您自己的后端,不要依赖推送通知。

标签: ios swift


【解决方案1】:

通知到达时将调用以下方法。

func didReceive(_ notification: UNNotification)

查看此苹果文档了解更多信息。 Notifications apple

【讨论】:

  • 谢谢,如果应用已经被终止了,有没有办法通过这种方法修改存储在Realm数据库等应用中的东西?
  • 如果应用程序被终止,它不会被调用,但如果应用程序在后台运行正常