Skip to content

Commit 03dd2c7

Browse files
committed
fix(type): Make badge NSNumber instead of NSInteger
* This let's us differentiate between null vs 0. The payload from APNS will be already be an NSNumber: https://developer.apple.com/documentation/usernotifications/unnotificationcontent/badge?language=objc * This fixes a bug when a notification had "SetTo" = 0, our check for the existence of notification.badge could not differentiate null vs 0, and we detected 0 as lack of existence. * Note: we will still cache and read badge count (ONESIGNAL_BADGE_KEY) as NSInteger since that is what we have been doing, and avoid having to change types / migration.
1 parent 3af1ea8 commit 03dd2c7

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
@property(readonly, nullable)NSString* category;
6060

6161
/* The badge assigned to the application icon */
62-
@property(readonly)NSInteger badge;
62+
@property(readonly, nullable)NSNumber* badge;
6363
@property(readonly)NSInteger badgeIncrement;
6464

6565
/* The sound parameter passed to the notification

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ - (void)parseCommonOneSignalFields:(NSDictionary*)payload {
124124

125125
- (void)parseApnsFields {
126126
[self parseAlertField:_rawPayload[@"aps"][@"alert"]];
127-
_badge = [_rawPayload[@"aps"][@"badge"] intValue];
127+
_badge = _rawPayload[@"aps"][@"badge"];
128128
_sound = _rawPayload[@"aps"][@"sound"];
129129
}
130130

@@ -145,7 +145,7 @@ - (void)parseAlertField:(NSObject*)alert {
145145
// May also be used if OneSignal server hasn't received the SDK version 2.4.0+ update event
146146
- (void)parseRemoteSlient:(NSDictionary*)payload {
147147
[self parseAlertField:payload[@"m"]];
148-
_badge = [payload[@"b"] intValue];
148+
_badge = payload[@"b"];
149149
_sound = payload[@"s"];
150150
_attachments = payload[@"at"];
151151
[self parseActionButtons:payload[@"o"]];
@@ -258,7 +258,7 @@ - (NSDictionary *)jsonRepresentation {
258258
[obj setObject:self.templateId forKeyedSubscript: @"templateId"];
259259

260260
if (self.badge)
261-
[obj setObject:@(self.badge) forKeyedSubscript: @"badge"];
261+
[obj setObject:self.badge forKeyedSubscript: @"badge"];
262262

263263
if (self.badgeIncrement)
264264
[obj setObject:@(self.badgeIncrement) forKeyedSubscript: @"badgeIncrement"];

iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalExtensionBadgeHandler.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ + (void)handleBadgeCountWithNotificationRequest:(UNNotificationRequest *)request
3535
//make sure the OneSignal cached value is updated to this value
3636
if (!notification.badgeIncrement) {
3737
if (notification.badge)
38-
[OneSignalExtensionBadgeHandler updateCachedBadgeValue:notification.badge];
38+
[OneSignalExtensionBadgeHandler updateCachedBadgeValue:notification.badge.intValue];
3939

4040
return;
4141
}

0 commit comments

Comments
 (0)