Exemplo n.º 1
0
        public int ScheduleNotification(string title, string message, double duration)
        {
            // EARLY OUT: app doesn't have permissions
            if (!hasNotificationsPermission)
            {
                return(-1);
            }

            messageId++;

            var content = new UNMutableNotificationContent()
            {
                Title    = title,
                Subtitle = "",
                Body     = message,
                Badge    = 1
            };

            Console.WriteLine("here");

            // Local notifications can be time or location based
            // Create a time-based trigger, interval is in seconds and must be greater than 0
            UNTimeIntervalNotificationTrigger trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(duration, false);

            UNNotificationRequest request = UNNotificationRequest.FromIdentifier(messageId.ToString(), content, trigger);

            UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) =>
            {
                if (err != null)
                {
                    throw new Exception($"Failed to schedule notification: {err}");
                }
                else
                {
                    Console.WriteLine("notification: " + request.ToString() + " made to notify in " + duration.ToString() + " seconds.");
                }
            });

            return(messageId);
        }