13

当用户收到通知并且我的应用程序在后台时,如何打开我的应用程序?当然点击通知本身会打开应用程序,但是如何使用自定义通知操作来处理它呢?

我已经实现了 UNUserNotificationCenterDelegate 和 userNotificationCenter(_, didReceive, ...)

只需要一个可以打开我的应用程序并执行特定操作的代码(例如转到特定视图)

如果通知处理程序能够识别该通知并打开 iPhone 应用程序或 Apple Watch 应用程序取决于点击操作的位置,那就太好了。

4

2 回答 2

22

好的,我找到了解决方案。我们必须设置 UNNotificationActionOptions :)

UNNotificationActionOptions.foreground
于 2016-09-30T08:18:55.503 回答
12

一个 Swift 3/4 示例(因为我不知道如何设置此选项):重要的UNNotificationActionOptionsUNNotificationAction.

let myAction = UNNotificationAction(identifier: "myActionIdentifier", title: "MyAction", options: [.foreground])
于 2017-01-10T22:39:48.510 回答