Application Badge is randomly cleared

I’m experiencing that the Application Badge for my app (on iPhone) is cleared sometimes for no apparent reason, then later set to the correct value.

Any idea what could cause this?

(I seem to remember there was a build.settings setting related to this, something about the badge being affected by other apps or something, but that was posted on the old forum.)

Hope someone knows the answer.

How is your badge being set in the first place?

Inside the application, it’s set manually like this:

[lua]

if string.len(badge) > 0 then

  native.setProperty(“applicationIconBadgeNumber”, badge)

end

[/lua]

And by the server like this:

$body = array(   "aps" =\> array(     "sound" =\> "push.caf",     "alert" =\> $message,     "badge" =\> intval($badge),   ), );

I’ve logged the values, and none of them are zero at the times when the badge disappeared.

I think it’s the push that erroneously clears it; at least going into the application (which sets it manually) always corrects the problem.

Are you interacting with the push notifications in any way?  Like touching the notification?

I send the push through APNS and iOS sets the badge. As far as I know, there is no way for Corona to interfere with the push when the app is in the background.

I am just wondering if this is a known issue or this configuration thing that I seem to remember from a year ago.

The OS can affect the badge count when you interact with the notifications.  But more importantly, what is intval($badge)?  Where is $badge being set?

And your app really doesn’t need to set the badge, iOS does that for you based on the badge value.   If you want your push to increment the badge, the badge should be the string “+1”.  If badge is “5”, that’s what the badge number will be set to after the push comes in regardless of the existing value.

I looked at it more, and it seems the badge is not set at all by the push. The notification event looks like below, and the badge value is clearly there, but it’s not picked up by iOS.

Again, is there any setting in build.settings or anything else that can come in the way of the push badge value?

[Lua]

table = {

  alert = “Test message”,

  applicationState = “inactive”,

  badge = 6,

  name = “notification”,

  sound = “push.caf”,

  type = “remote”,

  custom = {

  },

}

[/Lua]

As an experiment, I am now setting a fixed numeric value via the badge, and another fixed numeric value via the client.

Still, sometimes both these badge value are simply removed by a unknown, third force, which seems to happen randomly, a couple of times per day.

Is there anything, settings in build.settings, interference from other apps, anything, that can cause this?

There is nothing in build.settings, but if you get a push notification where badge = 0, it will clear your badge.

How is your badge being set in the first place?

Inside the application, it’s set manually like this:

[lua]

if string.len(badge) > 0 then

  native.setProperty(“applicationIconBadgeNumber”, badge)

end

[/lua]

And by the server like this:

$body = array(   "aps" =\> array(     "sound" =\> "push.caf",     "alert" =\> $message,     "badge" =\> intval($badge),   ), );

I’ve logged the values, and none of them are zero at the times when the badge disappeared.

I think it’s the push that erroneously clears it; at least going into the application (which sets it manually) always corrects the problem.

Are you interacting with the push notifications in any way?  Like touching the notification?

I send the push through APNS and iOS sets the badge. As far as I know, there is no way for Corona to interfere with the push when the app is in the background.

I am just wondering if this is a known issue or this configuration thing that I seem to remember from a year ago.

The OS can affect the badge count when you interact with the notifications.  But more importantly, what is intval($badge)?  Where is $badge being set?

And your app really doesn’t need to set the badge, iOS does that for you based on the badge value.   If you want your push to increment the badge, the badge should be the string “+1”.  If badge is “5”, that’s what the badge number will be set to after the push comes in regardless of the existing value.

I looked at it more, and it seems the badge is not set at all by the push. The notification event looks like below, and the badge value is clearly there, but it’s not picked up by iOS.

Again, is there any setting in build.settings or anything else that can come in the way of the push badge value?

[Lua]

table = {

  alert = “Test message”,

  applicationState = “inactive”,

  badge = 6,

  name = “notification”,

  sound = “push.caf”,

  type = “remote”,

  custom = {

  },

}

[/Lua]

As an experiment, I am now setting a fixed numeric value via the badge, and another fixed numeric value via the client.

Still, sometimes both these badge value are simply removed by a unknown, third force, which seems to happen randomly, a couple of times per day.

Is there anything, settings in build.settings, interference from other apps, anything, that can cause this?

There is nothing in build.settings, but if you get a push notification where badge = 0, it will clear your badge.

Rob,

I think there is errata in the documentation for IOS push notifications, specifically around the Notification Badges (iOS).  The documentation mentions sending “+1” in the notification to increment the badge.  I don’t believe that works for the push notification.  I suspect its only an Urban Airship push service feature.  I think you have to pass the badge value you want to have.

It could be.  UA may be tracking the badge value.  Though I think I tested that through PushWoosh and it worked.

Could be but stock APNS doesn’t support it so might be a good idea to indicate it in the docs.  Took a while to figure that out