Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
@property(readonly, nullable)NSString* category;

/* The badge assigned to the application icon */
/// Indicates if badge count is set on this notification; this flag is needed as the `badge` property is an
/// integer primitive and cannot be used to differentiate between null badge vs badge count of 0.
@property(readonly)BOOL hasBadge;
@property(readonly)NSInteger badge;
@property(readonly)NSInteger badgeIncrement;

Expand Down
5 changes: 4 additions & 1 deletion iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ - (void)parseCommonOneSignalFields:(NSDictionary*)payload {

- (void)parseApnsFields {
[self parseAlertField:_rawPayload[@"aps"][@"alert"]];
_hasBadge = _rawPayload[@"aps"][@"badge"] ? true : false;
_badge = [_rawPayload[@"aps"][@"badge"] intValue];
_sound = _rawPayload[@"aps"][@"sound"];
}
Expand Down Expand Up @@ -257,7 +258,9 @@ - (NSDictionary *)jsonRepresentation {
if (self.templateId)
[obj setObject:self.templateId forKeyedSubscript: @"templateId"];

if (self.badge)
[obj setObject:@(self.hasBadge) forKeyedSubscript: @"hasBadge"];

if (self.hasBadge)
[obj setObject:@(self.badge) forKeyedSubscript: @"badge"];

if (self.badgeIncrement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ + (void)handleBadgeCountWithNotificationRequest:(UNNotificationRequest *)request
//if the user is setting the badge directly instead of incrementing/decrementing,
//make sure the OneSignal cached value is updated to this value
if (!notification.badgeIncrement) {
if (notification.badge)
if (notification.hasBadge)
[OneSignalExtensionBadgeHandler updateCachedBadgeValue:notification.badge];

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ + (UNNotificationRequest*)prepareUNNotificationRequest:(OSNotification*)notifica
else
content.sound = UNNotificationSound.defaultSound;

if (notification.badge != 0)
if (notification.hasBadge)
content.badge = [NSNumber numberWithInteger:notification.badge];

// Check if media attached
Expand Down
Loading