Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ static BOOL IsNotificationRemote(UNNotification *notification)
return [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]];
}

// setBadgeCount: dispatch_syncs onto the UserNotifications connection queue, which another
// thread can hold for a whole usernotificationsd round trip. Serial so writes land in order.
static dispatch_queue_t RCTBadgeCountQueue(void)
{
static dispatch_queue_t queue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
queue = dispatch_queue_create(
"com.facebook.react.PushNotificationManager.badgeCount",
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0));
});
return queue;
}

RCT_EXPORT_MODULE()

- (dispatch_queue_t)methodQueue
Expand Down Expand Up @@ -324,13 +338,15 @@ - (void)setApplicationIconBadgeNumber:(double)number
{
NSInteger badgeCount = (NSInteger)lround(number);
if (@available(iOS 16.0, *)) {
[UNUserNotificationCenter.currentNotificationCenter
setBadgeCount:badgeCount
withCompletionHandler:^(NSError *_Nullable error) {
if (error != nil) {
RCTLogWarn(@"Failed to set application icon badge number: %@", error);
}
}];
dispatch_async(RCTBadgeCountQueue(), ^{
[UNUserNotificationCenter.currentNotificationCenter
setBadgeCount:badgeCount
withCompletionHandler:^(NSError *_Nullable error) {
if (error != nil) {
RCTLogWarn(@"Failed to set application icon badge number: %@", error);
}
}];
});
} else {
RCTSharedApplication().applicationIconBadgeNumber = badgeCount;
}
Expand Down
Loading