apns
apns copied to clipboard
Don't send badge value
Is it currently possible to not send a value for badge count? It seems to be the badge count is always sent since when it isn't explicitly set to something the library sets it to -1. I realize the issue here is differentiating between an empty badge count and a badge count set to zero. Two possible solutions would be to either make badge count an int pointer or create a method/flag on the payload that signals that the user wants to exclude the badge count. Thoughts?
I think I prefer the int pointer version. @anachronistic, what about you?
A third option exists which would be to treat badge numbers as such:
- badge == 0 - omit
- badge > 0 - set badge number
- badge < 0 - set badge number to -1 (which Apple treats as 0 on their end)
Just would need to heavily document that if you want to clear the badge number, you should set the badge to < 0 rather than 0.
This doesn't match one to one with Apple's spec but would alleviate the issue without changing the Payload interface.
As an update, ended up going with a typed solution and implementing json Marshaller interface (https://github.com/joekarl/go-libapns/blob/ccef56a3e7cb9f0f0da4add6da007a23ad0da46d/badge_number.go) props to @themartorana for that one