As per [ https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4 ] the proper notification format appears to be:
OutputStream os; // assuming this connection is valid/open
// header
os.write(command); // 1 byte | value of 2 in doc but 1 in notnoop/java-apns ?
os.write(frame_length); // 4 bytes | value of total size of frame items:
// item 1 - token
os.write(item_id_1); // 1 byte | value of 1
os.write(item_length_1); // 2 bytes | value of size of data (32 for token):
os.write(item_data_1); // 32 bytes | token data
// = total frame item size: 35
// item 2 - payload
os.write(item_id_2); // 1 byte | value of 2
os.write(item_length_2); // 2 bytes | value of size of data (175 for my payload):
os.write(item_data_2); // 175 bytes | payload data
// = total frame item size: 178
// item 3 - identifier
os.write(item_id_3); // 1 byte | value of 3
os.write(item_length_3); // 2 bytes | value of size of data (4)
os.write(item_data_3); // 4 byte | identifier data
// = total frame item size: 7
// item 4 - expiration date
os.write(item_id_4); // 1 byte | value of 4
os.write(item_length_4); // 2 bytes | value of size of data (4)
os.write(item_data_4); // 4 byte | expiration data
// = total frame item size: 7
// item 5 - priority
os.write(item_id_5); // 1 byte | value of 5
os.write(item_length_5); // 2 bytes | value of size of data (1):
os.write(item_data_5); // 1 byte | priority data
// = total frame item size: 4
Assuming that's all correct, that should give a frame data length total of: 35 + 178 + 7 + 7 + 4 = 232 by summing all of the frame item totals.
However in looking over some of the notnoop/java-apns code:
public byte[] marshall() {
if (marshall == null) {
marshall = Utilities.marshallEnhanced(COMMAND, identifier,
expiry, deviceToken, payload);
}
return marshall.clone();
}
public int length() {
int length = 1 + 4 + 4 + 2 + deviceToken.length + 2 + payload.length;
//1 = ?
//4 = identifier length
//4 = expiration length
//2 = ?
//32 = token length
//2 = ?
//x = payload length
final int marshalledLength = marshall().length;
assert marshalledLength == length;
return length;
}
I fail to see how this is calculating the length correctly. My code however does not work while this presumably does. What am I doing wrong?
First problem: I was examining an enhanced format (uses command 1) while trying to use a new format (uses command 2).
Second problem: I wasn't using some form of
ByteBuffering so the packet wasn't formed right.The total frame size calculations were correct in both cases.