File tree 4 files changed +9
-3
lines changed 4 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 59
59
@property (readonly , nullable )NSString * category;
60
60
61
61
/* 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;
62
65
@property (readonly )NSInteger badge;
63
66
@property (readonly )NSInteger badgeIncrement;
64
67
Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ - (void)parseCommonOneSignalFields:(NSDictionary*)payload {
124
124
125
125
- (void )parseApnsFields {
126
126
[self parseAlertField: _rawPayload[@" aps" ][@" alert" ]];
127
+ _hasBadge = _rawPayload[@" aps" ][@" badge" ] ? true : false ;
127
128
_badge = [_rawPayload[@" aps" ][@" badge" ] intValue ];
128
129
_sound = _rawPayload[@" aps" ][@" sound" ];
129
130
}
@@ -257,7 +258,9 @@ - (NSDictionary *)jsonRepresentation {
257
258
if (self.templateId )
258
259
[obj setObject: self .templateId forKeyedSubscript: @" templateId" ];
259
260
260
- if (self.badge )
261
+ [obj setObject: @(self .hasBadge) forKeyedSubscript: @" hasBadge" ];
262
+
263
+ if (self.hasBadge )
261
264
[obj setObject: @(self .badge) forKeyedSubscript: @" badge" ];
262
265
263
266
if (self.badgeIncrement )
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ + (void)handleBadgeCountWithNotificationRequest:(UNNotificationRequest *)request
34
34
// if the user is setting the badge directly instead of incrementing/decrementing,
35
35
// make sure the OneSignal cached value is updated to this value
36
36
if (!notification.badgeIncrement ) {
37
- if (notification.badge )
37
+ if (notification.hasBadge )
38
38
[OneSignalExtensionBadgeHandler updateCachedBadgeValue: notification.badge];
39
39
40
40
return ;
Original file line number Diff line number Diff line change @@ -985,7 +985,7 @@ + (UNNotificationRequest*)prepareUNNotificationRequest:(OSNotification*)notifica
985
985
else
986
986
content.sound = UNNotificationSound .defaultSound ;
987
987
988
- if (notification.badge != 0 )
988
+ if (notification.hasBadge )
989
989
content.badge = [NSNumber numberWithInteger: notification.badge];
990
990
991
991
// Check if media attached
You can’t perform that action at this time.
0 commit comments