Skip to content

Commit

Permalink
Added ios notification action icon support
Browse files Browse the repository at this point in the history
  • Loading branch information
thudugala committed Jun 5, 2024
1 parent 642ce19 commit e5acf43
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,36 @@ public void RegisterCategoryList(HashSet<NotificationCategory> categoryList)
continue;
}

var nativeAction = UNNotificationAction.FromIdentifier(
notificationAction.ActionId.ToString(CultureInfo.InvariantCulture), notificationAction.Title,
notificationAction.IOS.Action.ToNative());
nativeActionList.Add(nativeAction);
if (OperatingSystem.IsIOSVersionAtLeast(15))
{
var icon = notificationAction.IOS.Icon.Type switch
{
iOSActionIconType.None => null,
iOSActionIconType.System => UNNotificationActionIcon.CreateFromSystem(notificationAction.IOS.Icon.Name),
iOSActionIconType.Template => UNNotificationActionIcon.CreateFromTemplate(notificationAction.IOS.Icon.Name),
_ => null,
};

var nativeAction = UNNotificationAction.FromIdentifier(
notificationAction.ActionId.ToString(CultureInfo.InvariantCulture),
notificationAction.Title,
notificationAction.IOS.Action.ToNative(),
icon);

nativeActionList.Add(nativeAction);
}
else
{
var nativeAction = UNNotificationAction.FromIdentifier(
notificationAction.ActionId.ToString(CultureInfo.InvariantCulture),
notificationAction.Title,
notificationAction.IOS.Action.ToNative());

nativeActionList.Add(nativeAction);
}
}

if (nativeActionList.Any() == false)
if (nativeActionList.Count > 0)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Description>The local notification plugin provides a way to show local notifications from MAUI apps.</Description>
<PackageIcon>icon.png</PackageIcon>
<Copyright>Copyright © Elvin (Tharindu) Thudugala</Copyright>
<Version>11.1.2</Version>
<Version>11.1.3</Version>
<PackageReleaseNotes>Check: https://github.com/thudugala/Plugin.LocalNotification/releases </PackageReleaseNotes>
<IsPackable>True</IsPackable>

Expand Down
5 changes: 5 additions & 0 deletions Source/Plugin.LocalNotification/iOSOption/iOSAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public class iOSAction
///
/// </summary>
public iOSActionType Action { get; set; } = iOSActionType.None;

/// <summary>
/// An icon associated with an action.
/// </summary>
public iOSActionIcon Icon { get; set; } = new ();
}
}
18 changes: 18 additions & 0 deletions Source/Plugin.LocalNotification/iOSOption/iOSActionIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Plugin.LocalNotification.iOSOption
{
/// <summary>
///
/// </summary>
public class iOSActionIcon
{
/// <summary>
/// Defuat is None
/// </summary>
public iOSActionIconType Type { get; set; } = iOSActionIconType.None;

/// <summary>
/// Image Name
/// </summary>
public string Name { get; set; } = string.Empty;
}
}
20 changes: 20 additions & 0 deletions Source/Plugin.LocalNotification/iOSOption/iOSActionIconType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Plugin.LocalNotification.iOSOption
{
public enum iOSActionIconType

Check warning on line 3 in Source/Plugin.LocalNotification/iOSOption/iOSActionIconType.cs

View workflow job for this annotation

GitHub Actions / nuget

Missing XML comment for publicly visible type or member 'iOSActionIconType'

Check warning on line 3 in Source/Plugin.LocalNotification/iOSOption/iOSActionIconType.cs

View workflow job for this annotation

GitHub Actions / nuget

Missing XML comment for publicly visible type or member 'iOSActionIconType'

Check warning on line 3 in Source/Plugin.LocalNotification/iOSOption/iOSActionIconType.cs

View workflow job for this annotation

GitHub Actions / nuget

Missing XML comment for publicly visible type or member 'iOSActionIconType'
{
/// <summary>
/// No Image is set
/// </summary>
None,

/// <summary>
/// Creates an action icon by using a system symbol image.
/// </summary>
System,

/// <summary>
/// Creates an action icon based on an image in your app’s bundle, preferably in an asset catalog.
/// </summary>
Template
}
}

0 comments on commit e5acf43

Please sign in to comment.