【问题标题】:iOS 10 UNNotificationAction Open App from BackgroundiOS 10 UNNotificationAction 从后台打开应用
【发布时间】:2017-01-26 23:00:17
【问题描述】:

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

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

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

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

【问题讨论】:

  • 关于这个问题和建议的答案,我注意到developer.apple.com/documentation/usernotifications/… 说:“将此选项用于需要用户与您的应用进一步交互的操作。不要使用此选项只是为了带来你的应用程序到前台。”任何想法这有什么区别以及为什么重要?

标签: ios notifications action application-lifecycle usernotifications


【解决方案1】:

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

UNNotificationActionOptions.foreground

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-01
      • 1970-01-01
      相关资源
      最近更新 更多