iOS 10 UNNotificationAction从后台打开应用程序

Ada*_*aka 10 notifications action ios10 usernotifications

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

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

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

如果通知处理程序识别出通知并打开iPhone应用程序或Apple Watch应用程序取决于操作的位置,那将是很好的..

Ada*_*aka 18

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

UNNotificationActionOptions.foreground
Run Code Online (Sandbox Code Playgroud)


pal*_*lme 9

迅速3/4的例子(因为我不知道如何设置这个选项):重要的是UNNotificationActionOptionsUNNotificationAction.

let myAction = UNNotificationAction(identifier: "myActionIdentifier", title: "MyAction", options: [.foreground])
Run Code Online (Sandbox Code Playgroud)