【问题标题】:customDismissAction not working for remote notificationscustomDismissAction 不适用于远程通知
【发布时间】:2017-05-16 19:10:45
【问题描述】:

我正在尝试使用 iOS 上的自定义分析系统跟踪推送通知的打开和关闭,但我无法获得任何 UNNotificationDismissActionIdentifier 回复。

我在通知中心注册的代码:

if([[[UIDevice currentDevice] systemVersion] integerValue] >= 10){
    UNNotificationCategory* generalCategory = [UNNotificationCategory
                                               categoryWithIdentifier:@"GENERAL"
                                               actions:@[]
                                               intentIdentifiers:@[]
                                               options:UNNotificationCategoryOptionCustomDismissAction];

    // Register the notification categories.
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    [center setNotificationCategories:[NSSet setWithObjects:generalCategory, nil]];
    [center setDelegate:self];
};

当我发送推送通知时,我将类别设置为 GENERAL。当我收到通知并向右滑动以将其关闭时,我没有收到任何委托回调。

customDismissAction 是否仅适用于本地通知?

【问题讨论】:

  • 你运气好吗?不要customDismissAction 假设您应该将一些操作传递给初始化程序?
  • 你能告诉我们你的有效载荷结构吗? category 是写在aps 键下吗?
  • 您是否在整个应用程序中调用一次setNotificationCategories‍‍‍?无论何时调用它,它都会替换以前的类别。因此,在注册后,您应该准备好所有类别

标签: ios objective-c notifications


【解决方案1】:

遇到了同样的问题。 documentation 提到这需要成为远程通知的 APS 有效负载的一部分。在我发现/拿起它之前,我必须仔细阅读它。确保将您想要的任何类别添加到推送有效负载中,并在注册解除操作时使其匹配。因此,如果您使用示例“GENERAL”,则有效负载应包含该类别

"aps" : {
  "category" : "GENERAL",
  "alert" : {
     "body" : "Some message",
  },
  etc...
}

【讨论】:

    猜你喜欢
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多