Skip to content

Commit 3b84b0e

Browse files
committed
add action icons to notification actions
1 parent 6388014 commit 3b84b0e

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,16 +566,33 @@ + (UNNotificationRequest*)prepareUNNotificationRequest:(OSNotification*)notifica
566566
return [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
567567
}
568568

569+
+ (UNNotificationAction *)createActionForButton:(NSDictionary *)button {
570+
if (@available(iOS 15.0, *)) {
571+
UNNotificationActionIcon *icon;
572+
if (button[@"systemIcon"]) {
573+
icon = [UNNotificationActionIcon iconWithSystemImageName:button[@"systemIcon"]];
574+
} else if (button[@"templateIcon"]) {
575+
icon = [UNNotificationActionIcon iconWithTemplateImageName:button[@"templateIcon"]];
576+
}
577+
return [UNNotificationAction actionWithIdentifier:button[@"id"]
578+
title:button[@"text"]
579+
options:UNNotificationActionOptionForeground
580+
icon:icon];
581+
} else {
582+
return [UNNotificationAction actionWithIdentifier:button[@"id"]
583+
title:button[@"text"]
584+
options:UNNotificationActionOptionForeground];
585+
}
586+
}
587+
569588
+ (void)addActionButtons:(OSNotification*)notification
570589
toNotificationContent:(UNMutableNotificationContent*)content {
571590
if (!notification.actionButtons || notification.actionButtons.count == 0)
572591
return;
573592

574593
let actionArray = [NSMutableArray new];
575594
for(NSDictionary* button in notification.actionButtons) {
576-
let action = [UNNotificationAction actionWithIdentifier:button[@"id"]
577-
title:button[@"text"]
578-
options:UNNotificationActionOptionForeground];
595+
let action = [self createActionForButton:button];
579596
[actionArray addObject:action];
580597
}
581598

0 commit comments

Comments
 (0)