-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alert is serialized to JSON even if all fields are blank. #5
Comments
The use case for this is for Passbook and Newstand notifications. Timehop APNS currently sends: {"aps":{"alert":{}}}
{"aps":{"alert":{},"content-available":1}} Whereas Grocer doesn't include "Alert": {"aps": {}}
{"aps": {"content-available":1}} It looks like omitting the Alert is the intended behaviour: Alert Alert `json:"alert,omitempty"` But apparently |
mgo/bson does an IsZero check on all the fields of a struct to decide whether to omit it: Making Alert into a pointer would be more efficient. NewPayload could allocate Alert, so it would need to be explicitly set to nil by the caller to skip it. An alternative would be to have different payloads/notification types for different things (like Grocer), such as a PassbookNotification with no payload. Before going down either of these roads, has anyone confirmed that Apple doesn't accept |
Regarding your suggestions: I think it would be awesome if we could avoid reflection, and definitely better if we could avoid application-presumptive code. For example, my use case for empty alerts has nothing to do with passbook, but I still don't want an alert. Apple does accept empty alert structs in my use case. However, the payload size is highly restricted at 255 bytes, and I'd advocate for some custom implementation of |
I need to verify if this is necessary for the Passbook case before making any change. It might not be a big deal for us either (I don't think we have the same 255 byte limit here, not since the v2 api). I'm also trying to find out how to fix the tests #8 before proceeding. |
I think we can do this without reflection. I'll give it a shot. |
I think it's because it's a struct. One thought is to make it a pointer, but that adds some complexity to the user.
If we wanted to avoid complexity for the user, we could do our own serialization entirely to make sure the alert isn't serialized unless it needs to be. We could probably do that as a method on the Alert itself, which would be neat. That adds complexity to the lib though.
The text was updated successfully, but these errors were encountered: