File tree Expand file tree Collapse file tree 4 files changed +9
-3
lines changed Expand file tree Collapse file tree 4 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 5959@property (readonly , nullable )NSString * category;
6060
6161/* The badge assigned to the application icon */
62+ // / Indicates if badge count is set on this notification; this flag is needed as the `badge` property is an
63+ // / integer primitive and cannot be used to differentiate between null badge vs badge count of 0.
64+ @property (readonly )BOOL hasBadge;
6265@property (readonly )NSInteger badge;
6366@property (readonly )NSInteger badgeIncrement;
6467
Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ - (void)parseCommonOneSignalFields:(NSDictionary*)payload {
124124
125125- (void )parseApnsFields {
126126 [self parseAlertField: _rawPayload[@" aps" ][@" alert" ]];
127+ _hasBadge = _rawPayload[@" aps" ][@" badge" ] ? true : false ;
127128 _badge = [_rawPayload[@" aps" ][@" badge" ] intValue ];
128129 _sound = _rawPayload[@" aps" ][@" sound" ];
129130}
@@ -257,7 +258,9 @@ - (NSDictionary *)jsonRepresentation {
257258 if (self.templateId )
258259 [obj setObject: self .templateId forKeyedSubscript: @" templateId" ];
259260
260- if (self.badge )
261+ [obj setObject: @(self .hasBadge) forKeyedSubscript: @" hasBadge" ];
262+
263+ if (self.hasBadge )
261264 [obj setObject: @(self .badge) forKeyedSubscript: @" badge" ];
262265
263266 if (self.badgeIncrement )
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ + (void)handleBadgeCountWithNotificationRequest:(UNNotificationRequest *)request
3434 // if the user is setting the badge directly instead of incrementing/decrementing,
3535 // make sure the OneSignal cached value is updated to this value
3636 if (!notification.badgeIncrement ) {
37- if (notification.badge )
37+ if (notification.hasBadge )
3838 [OneSignalExtensionBadgeHandler updateCachedBadgeValue: notification.badge];
3939
4040 return ;
Original file line number Diff line number Diff line change @@ -985,7 +985,7 @@ + (UNNotificationRequest*)prepareUNNotificationRequest:(OSNotification*)notifica
985985 else
986986 content.sound = UNNotificationSound .defaultSound ;
987987
988- if (notification.badge != 0 )
988+ if (notification.hasBadge )
989989 content.badge = [NSNumber numberWithInteger: notification.badge];
990990
991991 // Check if media attached
You can’t perform that action at this time.
0 commit comments