首页 文章

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

提问于
浏览
9

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

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

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

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

2 回答

  • 8

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

    UNNotificationActionOptions.foreground
    
  • 15

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

    let myAction = UNNotificationAction(identifier: "myActionIdentifier", title: "MyAction", options: [.foreground])
    

相关问题