【问题标题】:UNNotificationAction sometimes not showing in remote notificationUNNotificationAction 有时不会显示在远程通知中
【发布时间】:2020-01-22 11:15:06
【问题描述】:

我已经在 appdelegate 中使用标识符注册了 UNNotificationAction,我还在通知扩展的 info.plist 中添加了该标识符。如果我安装应用程序,按钮是可见的,在杀死应用程序按钮后是不可见的。我还与类别标识符进行了交叉检查。它在示例应用程序中运行良好,但是当我将它集成到应用程序中时,它的行为很奇怪。

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:@"next"
                                                                        title:actionTitle1
                                                                      options:UNNotificationActionOptionNone];
    UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"goto"
                                                                         title:actionTitle2
                                                                       options:UNNotificationActionOptionNone];
    UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"category_identifier"
                                                                              actions:@[action,action2] intentIdentifiers:@[]
                                                                              options:UNNotificationCategoryOptionNone];
    NSSet *categories = [NSSet setWithObject:category];
    [center setNotificationCategories:categories];

【问题讨论】:

  • 您如何将其实际集成到您的应用中?尝试在每次应用启动时调用它。
  • 我只在 didFinishLunch 中添加了它。

标签: ios apple-push-notifications unnotificationscontentextension


【解决方案1】:

我多次调用 setNotificationCategories,这就是 UNNotificationAction 没有显示的原因。

【讨论】:

    猜你喜欢
    • 2017-11-06
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 2020-05-06
    相关资源
    最近更新 更多