iOS 警报行为与相同的 APNS 消息不一致

标签 ios notifications push amazon-sns

服务器端的家伙在这里。

我向同一台设备发送完全相同的 APNS 负载,但我看到了不同的结果:

  1. 手机亮起,显示警报
  2. 手机亮了,没有提示

据我所知这是随机的。有时手机会显示警报,有时不会。但在所有情况下,APNS 消息都是相同的。

这两种情况都会随机发生。尽管我很努力,但我无法重现模式。

APNS 负载在两种情况下看起来相同:

{
  "aps": {
    "alert": "Blah Blah Blah something useful happened",
    "badge": 0
  }
}

我想弄清楚的是,问题出在哪里?这是 iOS 客户端问题还是服务器端问题?

到目前为止,我已经能够使用以下推送服务重现该问题:

  • 亚马逊社交网站
  • Urban Airship
  • 解析
  • 推锐

iOS 是否对通知做了一些我不知道的事情?这是 APNS 问题吗?有效载荷包搞砸了吗?还是申请的问题?

最佳答案

好的,我找到了答案。

如果目标设备的角标(Badge)计数大于 0,并且发送了角标(Badge)计数为 0 的通知,iOS 会清除应用程序发出的所有通知。这会导致屏幕快速闪烁而不会显示通知。

要复制,请将其发送到设备以使角标(Badge)计数:

{
  "aps": {
    "alert": "this notif will show up",
    "badge": 2
  }
}

然后,发送这个有效载荷,notif 将不会显示:

{
  "aps": {
    "alert": "this notif will not show up",
    "badge": 0
  }
}

Apple 在他们的文档中有一条关于角标(Badge)的快速行,“要删除角标(Badge),请将此属性的值设置为 0。”这不仅仅是删除角标(Badge),而是阻止显示发送通知并清除可能仍未读的所有先前通知。

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1

关于iOS 警报行为与相同的 APNS 消息不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24092380/

相关文章:

ios - Swift Firebase Storage.storage().reference(forURL : ) not working

ios - react native : SyntaxError: Strict mode does not allow function declarations in a lexically nested statement

ios - 使用计时器安排通知触发

ios:横向模式下两个 View Controller 之间的自定义 Segue

iphone - 提取NSCFConstantString的第一项

ios - 如果来自 UIViewController 的对象如何仅获取我创建的自定义属性的名称(在运行时)?

ios - iOS 中的蓝牙 LE 和 ANCS

ios - Swift - UNUsernotification 检查 BadgeNumberIcon 中的更改

version-control - 你能阻止默认推送,但允许拉吗?

java - 解析推送通知安装错误