From 481e3ec53af4044715cfa71ec03984c5b49af63c Mon Sep 17 00:00:00 2001 From: TJ Lambert <50846373+tj-devel709@users.noreply.github.com> Date: Tue, 26 Jul 2022 10:40:12 -0500 Subject: [PATCH] [Fix] Reorder the enum to the correct order (#15540) Co-authored-by: TJ Lambert --- src/usernotifications.cs | 23 +++++++++++-- .../NotificationInterruptionLevel.cs | 32 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tests/monotouch-test/UserNotifications/NotificationInterruptionLevel.cs diff --git a/src/usernotifications.cs b/src/usernotifications.cs index 0f572db084..116023f9bc 100644 --- a/src/usernotifications.cs +++ b/src/usernotifications.cs @@ -171,10 +171,29 @@ namespace UserNotifications { [Native] public enum UNNotificationInterruptionLevel : long { - Active, - Critical, +#if XAMCORE_5_0 Passive, + Active, TimeSensitive, + Critical, +#else + [Obsolete ("Use 'Active2'.")] + Active, + [Obsolete ("Use 'Critical2'.")] + Critical, + [Obsolete ("Use 'Passive2'.")] + Passive, + [Obsolete ("Use 'TimeSensitive2'.")] + TimeSensitive, +#endif // XAMCORE_5_0 + + // Additional enum values to fix reordering - to be at the end of the enum +#if !XAMCORE_5_0 + Active2 = Critical, + Critical2 = TimeSensitive, + Passive2 = Active, + TimeSensitive2 = Passive, +#endif // !XAMCORE_5_0 } [iOS (10, 0)] diff --git a/tests/monotouch-test/UserNotifications/NotificationInterruptionLevel.cs b/tests/monotouch-test/UserNotifications/NotificationInterruptionLevel.cs new file mode 100644 index 0000000000..e81de7474e --- /dev/null +++ b/tests/monotouch-test/UserNotifications/NotificationInterruptionLevel.cs @@ -0,0 +1,32 @@ +using System; +using NUnit.Framework; + +using Foundation; +using UserNotifications; + +namespace MonoTouchFixtures.UserNotifications { + + [TestFixture] + [Preserve (AllMembers = true)] + public class UNNotificationInterruptionLevelTest { + + [Test] + public void EnumTest () + { +#if !XAMCORE_5_0 + /* Apple Docs order these enum values as: + typedef NS_ENUM (NSUInteger, UNNotificationInterruptionLevel) + { + UNNotificationInterruptionLevelPassive, + UNNotificationInterruptionLevelActive, + UNNotificationInterruptionLevelTimeSensitive, + UNNotificationInterruptionLevelCritical, + } */ + Assert.AreEqual ( (int)UNNotificationInterruptionLevel.Passive2, 0); + Assert.AreEqual ( (int)UNNotificationInterruptionLevel.Active2, 1); + Assert.AreEqual ( (int)UNNotificationInterruptionLevel.TimeSensitive2, 2); + Assert.AreEqual ( (int)UNNotificationInterruptionLevel.Critical2, 3); +#endif + } + } +}