katit katit - 1 year ago 39
iOS Question

Apple push notifications with Version 2 - limits and questions

Just starting to learn and implement our server for sending push notifications in C#
I read following: Apple Push Notifications in Bulk
I also checked push-sharp and MoonApns projects for code reference.

Both projects use version "1" of message.

Apple has new format (2) here:

I don't have reference to v1 to compare but by looking online it seems like they added ability to send "batch" of messages at one time. So, we don't have to send each notification one by one, we instead can send packs..

Being new and overwhelmed with all this as it is I wonder if I should try and deal with v2?

  1. Seeing that ItemId is 1 byte - we can't send more than 256 messages in one batch, right? What ItemId is good for? Should it start with 1? Should they increment?

  2. If I get error, it will specify NotificationIdentifier, will it work the same if, for example I sent batch of 100 messages and message 50 returned as error. I should resent remaining 50? Or whole batch?

I guess question is WHY? Why this new format? For better performance with multiple messages? I think even if I dump messages without waiting as v1 it will be more than enough for our use.

Answer Source
  1. ItemId is not the identifier of the notification. It identifies the type of the Item (1 for device token, 2 for payload, 3 for notification identifier, 4 for expiration data and 5 for priority). Therefore it has no effect on the number of messages sent in one batch.

  2. If message 50 has an error, you have to resend messages 51 - 100.

I haven't tried to use this new format, and I'm not sure what it's good for. It adds the notification priority, which didn't exist in the previous format, but if you don't need that, you can stick with format 1.

BTW, from the current documentation it's unclear how you are supposed to batch notifications using the new format.

A single frame must include (at least) all the items of a single notification (i.e. device token, payload, message ID, expiration and priority), unless some of them are optional (which is not specified in the documentation).

But if you include only one notification in a frame, you don't batch anything. If you attempt to include multiple notifications in a single frame, it is not clear how the frame would be interpreted. The need to specify the item type for each item implies that the order of the items doesn't matter (unlike formats 0 and 1 in which it did). So if, for example, you decide to batch two notifications in the same frame, you'll have two notification IDs and two device tokens in the same frame. In this case, it's not clear which device token relates to which notification ID (unless the order does matter). Perhaps that format is an intermediate format that would be extended later on to allow sending a single payload to multiple device tokens (which will allow you to specify the payload once for multiple device tokens). That would be useful.

Formats 0 and 1 are specified here.