Skip to content

Commit

Permalink
add action icons to notification actions
Browse files Browse the repository at this point in the history
  • Loading branch information
emawby committed Sep 3, 2021
1 parent d72573b commit 506f2f9
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,33 @@ + (UNNotificationRequest*)prepareUNNotificationRequest:(OSNotification*)notifica
return [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
}

+ (UNNotificationAction *)createActionForButton:(NSDictionary *)button {
if (@available(iOS 15.0, *)) {
UNNotificationActionIcon *icon;
if (button[@"systemIcon"]) {
icon = [UNNotificationActionIcon iconWithSystemImageName:button[@"systemIcon"]];
} else if (button[@"templateIcon"]) {
icon = [UNNotificationActionIcon iconWithTemplateImageName:button[@"templateIcon"]];
}
return [UNNotificationAction actionWithIdentifier:button[@"id"]
title:button[@"text"]
options:UNNotificationActionOptionForeground
icon:icon];
} else {
return [UNNotificationAction actionWithIdentifier:button[@"id"]
title:button[@"text"]
options:UNNotificationActionOptionForeground];
}
}

+ (void)addActionButtons:(OSNotification*)notification
toNotificationContent:(UNMutableNotificationContent*)content {
if (!notification.actionButtons || notification.actionButtons.count == 0)
return;

let actionArray = [NSMutableArray new];
for(NSDictionary* button in notification.actionButtons) {
let action = [UNNotificationAction actionWithIdentifier:button[@"id"]
title:button[@"text"]
options:UNNotificationActionOptionForeground];
let action = [self createActionForButton:button];
[actionArray addObject:action];
}

Expand Down

0 comments on commit 506f2f9

Please sign in to comment.