Skip to content

Commit 26a4189

Browse files
committed
OneSignal notification buttons not displaying fix
* Re-listing notifications categories after registering to force a refresh of them. - See comment for more details. * These are the dynamic per notification buttons set via the dashboard or REST API * Issue started to show up in iOS 12 * Fixes #430
1 parent ac76834 commit 26a4189

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,26 +666,31 @@ + (void)addActionButtons:(OSNotificationPayload*)payload
666666
var allCategories = OneSignalNotificationCategoryController.sharedInstance.existingCategories;
667667

668668
let newCategoryIdentifier = [OneSignalNotificationCategoryController.sharedInstance registerNotificationCategoryForNotificationId:payload.notificationID];
669-
670669
let category = [UNNotificationCategory categoryWithIdentifier:newCategoryIdentifier
671670
actions:finalActionArray
672671
intentIdentifiers:@[]
673672
options:UNNotificationCategoryOptionCustomDismissAction];
674-
673+
675674
if (allCategories) {
676675
let newCategorySet = [NSMutableSet new];
677676
for(UNNotificationCategory *existingCategory in allCategories) {
678677
if (![existingCategory.identifier isEqualToString:newCategoryIdentifier])
679678
[newCategorySet addObject:existingCategory];
680679
}
681-
680+
682681
[newCategorySet addObject:category];
683682
allCategories = newCategorySet;
684683
}
685684
else
686685
allCategories = [[NSMutableSet alloc] initWithArray:@[category]];
686+
687+
[UNUserNotificationCenter.currentNotificationCenter setNotificationCategories:allCategories];
687688

688-
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:allCategories];
689+
// List Categories again so iOS refreshes it's internal list.
690+
// Required otherwise buttons will not display or won't update.
691+
// This is a blackbox assumption, the delay on the main thread this call creates might be giving
692+
// some iOS background thread time to flush to disk.
693+
allCategories = OneSignalNotificationCategoryController.sharedInstance.existingCategories;
689694

690695
content.categoryIdentifier = newCategoryIdentifier;
691696
}

iOS_SDK/OneSignalSDK/Source/OneSignalNotificationCategoryController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ - (NSString *)registerNotificationCategoryForNotificationId:(NSString *)notifica
9898
return categoryId;
9999
}
100100

101+
// Get all existing Notifications Categories in a blocking way
101102
- (NSMutableSet<UNNotificationCategory*>*)existingCategories {
102103
__block NSMutableSet* allCategories;
103104
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

0 commit comments

Comments
 (0)