UNNotificationAction 有时不显示在远程通知中

UNNotificationAction sometimes not showing in remote notification

我已经在 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];

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