apns icon indicating copy to clipboard operation
apns copied to clipboard

Don't send badge value

Open MrTravisB opened this issue 10 years ago • 3 comments

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?

MrTravisB avatar Sep 10 '14 19:09 MrTravisB

I think I prefer the int pointer version. @anachronistic, what about you?

draaglom avatar Sep 12 '14 00:09 draaglom

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.

joekarl avatar Jan 13 '15 23:01 joekarl

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

joekarl avatar Feb 14 '15 03:02 joekarl