using System; namespace Unity.Notifications.iOS { /// /// Options for notification actions. /// These represent values from UNNotificationActionOptions. /// For more information, refer to Apple documentation. /// [Flags] public enum iOSNotificationActionOptions { /// /// No specific action is performed. /// None = 0, /// /// An action that requires the user to unlock their device. /// Required = (1 << 0), /// /// An irreversible action such as deleting data. /// Destructive = (1 << 1), /// /// An action that opens the application. /// Foreground = (1 << 2), } enum iOSNotificationActionIconType { None = 0, SystemImageName = 1, TemplateImageName = 2, } /// /// Represents action for an actionable notification. /// Actions are supposed to be added to notification categories, which are then registered prior to sending notifications. /// User can choose to tap a notification or one of associated actions. Application gets feedback of the choice. /// /// /// public class iOSNotificationAction { internal iOSNotificationActionIconType _imageType; internal string _image; /// /// An identifier for this action. /// Each action within an application unique must have unique ID. /// This ID will be returned by iOSNotificationCenter.GetLastRespondedNotificationAction if user chooses this action. /// public string Id { get; set; } /// /// Title for the action. /// This will be the title of the button that appears below the notification. /// public string Title { get; set; } /// /// Options for the action. Can be a combination of given flags. /// Refer to Apple documentation for UNNotificationActionOptions for exact meanings. /// /// public iOSNotificationActionOptions Options { get; set; } /// /// Set the icon for action using system symbol image name. /// /// public string SystemImageName { get { return _imageType == iOSNotificationActionIconType.SystemImageName ? _image : null; } set { _imageType = iOSNotificationActionIconType.SystemImageName; _image = value; } } /// /// Set the icon for action using image from app's bundle. /// /// public string TemplateImageName { get { return _imageType == iOSNotificationActionIconType.TemplateImageName ? _image : null; } set { _imageType = iOSNotificationActionIconType.TemplateImageName; _image = value; } } /// /// Creates new action. /// /// Unique identifier for this action /// Title for the action (and button label) public iOSNotificationAction(string id, string title) : this(id, title, 0) { } /// /// Creates new action. /// /// Unique identifier for this action /// Title for the action (and button label) /// Options for the action public iOSNotificationAction(string id, string title, iOSNotificationActionOptions options) { Id = id; Title = title; Options = options; } internal virtual IntPtr CreateUNNotificationAction() { #if UNITY_IOS && !UNITY_EDITOR return iOSNotificationsWrapper._CreateUNNotificationAction(Id, Title, (int)Options, (int)_imageType, _image); #else return IntPtr.Zero; #endif } } /// /// Represents a special notification action with text input support. /// Each action within an application unique must have unique ID. /// When user chooses this action, a prompt for text input appears. /// If this action is responded to by the user, iOSNotificationCenter.GetLastRespondedNotificationAction will return it's ID, /// while iOSNotificationCenter.GetLastRespondedNotificationUserText will return the text entered. /// public class iOSTextInputNotificationAction : iOSNotificationAction { /// /// Text label for the button for submitting the text input. /// public string TextInputButtonTitle { get; set; } /// /// The placeholder text for input. /// public string TextInputPlaceholder { get; set; } /// /// Creates new text input action. /// /// Unique identifier for this action /// Title for the action (and button label) /// Label for a button for submitting the text input public iOSTextInputNotificationAction(string id, string title, string buttonTitle) : base(id, title) { TextInputButtonTitle = buttonTitle; } /// /// Creates new text input action. /// /// Unique identifier for this action /// Title for the action (and button label) /// Options for the action /// Label for a button for submitting the text input public iOSTextInputNotificationAction(string id, string title, iOSNotificationActionOptions options, string buttonTitle) : base(id, title, options) { TextInputButtonTitle = buttonTitle; } internal override IntPtr CreateUNNotificationAction() { #if UNITY_IOS && !UNITY_EDITOR return iOSNotificationsWrapper._CreateUNTextInputNotificationAction(Id, Title, (int)Options, (int)_imageType, _image, TextInputButtonTitle, TextInputPlaceholder); #else return IntPtr.Zero; #endif } } }