【发布时间】:2021-12-23 05:22:26
【问题描述】:
我见过很多类似的问题,但在 Mac 上运行时我还没有找到这个特定场景的答案。 如果应用程序关闭并且用户通知进入并且用户点击它,则应用程序被打开。应用打开后,如何捕获通知以便处理其内容。
据我所知,无法从[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler: 或[[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler: 检索通知。
当用户点击通知打开应用程序时,它似乎也没有通过UNUserNotificationCenterDelegate 函数打开。我在 willPresentNotification 或 didReceiveNotificationResponse 中都没有看到它,并且它不是由 appDelegate 的 didReceiveRemoteNotification:fetchCompletionHandler 处理的。
在这种情况下,在 iOS 上,通知从application:didFinishLaunchingWithOptions 到达launchOptions。有键UIApplicationLaunchOptionsRemoteNotificationKey 包含通知数据。在 Mac 上运行的同一个应用程序包含一个 nil launchOptions 字典。
这些都是我看过的所有地方,但我确定我一定错过了什么。
【问题讨论】:
标签: ios objective-c mac-catalyst unusernotificationcenter usernotifications