新的命令2苹果推送通知不发送多个警报

我正在尝试在Java中实现新的“Command 2”推送通知,并且不能推送多个警报。 第一个提醒被成功推送。 如果你能发现这个代码的任何问题,请帮助

Apple规格https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW1

for (DeviceApps deviceApps : deviceAppsList) { outputStream.write(getByteArray(deviceApps, pushAlert)); } private byte[] getByteArray(DeviceApps deviceApps, PushAlert pushAlert) { ByteArrayOutputStream dataBao = new ByteArrayOutputStream(); // Write the TokenLength as a 16bits unsigned int, in big endian dataBao.write((byte)1); dataBao.write(intTo2ByteArray(32)); dataBao.write(deviceTokenAsBytes); // Write the PayloadLength as a 16bits unsigned int, in big endian dataBao.write((byte)2); dataBao.write(intTo2ByteArray(payLoadAsBytes.length)); dataBao.write(payLoadAsBytes); // 4 bytes. Notification identifier dataBao.write((byte)3); dataBao.write(intTo2ByteArray(4)); dataBao.write(intTo4ByteArray(random.nextInt())); // 4 bytes Expiration date dataBao.write((byte)4); dataBao.write(intTo2ByteArray(4)); dataBao.write(intTo4ByteArray(pushAlert.getUtcExpireTime())); LOG.error("UtcExpireTime="+ pushAlert.getUtcExpireTime()); // 1 bytes Priority dataBao.write((byte)5); dataBao.write(intTo2ByteArray(1)); dataBao.write((byte)10); //Frame Info bao = new ByteArrayOutputStream(); bao.write((byte)2); byte [] data = dataBao.toByteArray(); bao.write(intTo4ByteArray(data.length)); LOG.error(" data.length "+data.length); bao.write(data); return bao.toByteArray(); } Support Methods private static final byte[] intTo4ByteArray(int value) { return ByteBuffer.allocate(4).putInt(value).array(); } private static final byte[] intTo2ByteArray(int value) { int s1 = (value & 0xFF00) >> 8; int s2 = value & 0xFF; return new byte[] { (byte) s1, (byte) s2 }; } 

由于你从APNS得到一个错误代码,连接应该在这个时候被丢弃,并且在错误之后,APNS将忽略所有的事情。 当您收到错误时,标识符就是您当前使用的随机数的标识符。

在这里没有简单的解决scheme – 你必须重新构build你有什么,所以当你收到错误,你可以找出所有点后重新发送 – 我build议使用一个序列号的标识符,然后存储数据包在一个队列中,你周期性的清除(你必须保持在30秒左右,以保证苹果接受他们)。

它看起来像你正在写一个通知bao ,所以你为什么期望它推动多个警报? 如果您想要推送多个警报,则必须重复多次写入bao的字节序列。

命令2和帧数据长度适用于每个消息。 如果在一个连接中发送多个消息,则对于每个消息:发送命令2,消息的帧数据长度以及5个部分(令牌,有效载荷,ID,过期,优先级)