using System; using System.Linq; namespace NotificationSamples { /// /// Cross-platform wrapper to represent channels for notifications. /// /// /// On Android, this maps pretty closely to Android Notification Channels. On iOS, this does nothing. /// For projects targeting Android, you need to have at least one channel. /// public struct GameNotificationChannel { /// /// The style of notification shown for this channel. Corresponds to the Importance setting of /// an Android notification, and do nothing on iOS. /// public enum NotificationStyle { /// /// Notification does not appear in the status bar. /// None = 0, /// /// Notification makes no sound. /// NoSound = 2, /// /// Notification plays sound. /// Default = 3, /// /// Notification also displays a heads-up popup. /// Popup = 4 } /// /// Controls how notifications display on the device lock screen. /// public enum PrivacyMode { /// /// Notifications aren't shown on secure lock screens. /// Secret = -1, /// /// Notifications display an icon, but content is concealed on secure lock screens. /// Private = 0, /// /// Notifications display on all lock screens. /// Public } /// /// The identifier for the channel. /// public readonly string Id; /// /// The name of the channel as displayed to the user. /// public readonly string Name; /// /// The description of the channel as displayed to the user. /// public readonly string Description; /// /// A flag determining whether messages on this channel can show a badge. Defaults to true. /// public readonly bool ShowsBadge; /// /// A flag determining whether messages on this channel cause the device light to flash. Defaults to false. /// public readonly bool ShowLights; /// /// A flag determining whether messages on this channel cause the device to vibrate. Defaults to true. /// public readonly bool Vibrates; /// /// A flag determining whether messages on this channel bypass do not disturb settings. Defaults to false. /// public readonly bool HighPriority; /// /// The display style for this notification. Defaults to . /// public readonly NotificationStyle Style; /// /// The privacy setting for this notification. Defaults to . /// public readonly PrivacyMode Privacy; /// /// The custom vibration pattern for this channel. Set to null to use the default. /// public readonly int[] VibrationPattern; /// /// Initialize a new instance of with /// optional fields set to their default values. /// public GameNotificationChannel(string id, string name, string description) : this() { Id = id; Name = name; Description = description; ShowsBadge = true; ShowLights = false; Vibrates = true; HighPriority = false; Style = NotificationStyle.Popup; Privacy = PrivacyMode.Public; VibrationPattern = null; } /// /// Initialize a new instance of , providing the notification style /// and optionally all other settings. /// public GameNotificationChannel(string id, string name, string description, NotificationStyle style, bool showsBadge = true, bool showLights = false, bool vibrates = true, bool highPriority = false, PrivacyMode privacy = PrivacyMode.Public, long[] vibrationPattern = null) { Id = id; Name = name; Description = description; ShowsBadge = showsBadge; ShowLights = showLights; Vibrates = vibrates; HighPriority = highPriority; Style = style; Privacy = privacy; if (vibrationPattern != null) VibrationPattern = vibrationPattern.Select(v => (int)v).ToArray(); else VibrationPattern = null; } } }