Exemplo n.º 1
0
 public override int ScheduleLocalNotification(string body, int delay)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
     {
         UNUserNotificationCenter     center  = UNUserNotificationCenter.Current;
         UNMutableNotificationContent content = new UNMutableNotificationContent();
         content.Body  = body;
         content.Sound = UNNotificationSound.Default;
         UNTimeIntervalNotificationTrigger trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(delay, false);
         UNNotificationRequest             request = UNNotificationRequest.FromIdentifier(StringIdentifierFromInt(LocalNotificationUid), content, trigger);
         center.AddNotificationRequest(request, (NSError error) =>
         {
             if (error != null)
             {
                 Console.WriteLine("Something went wrong:" + error);
             }
         });
     }
     else
     {
         UILocalNotification localNotification = new UILocalNotification();
         localNotification.FireDate  = NSDate.FromTimeIntervalSinceNow(delay);
         localNotification.AlertBody = body;
         localNotification.TimeZone  = NSTimeZone.DefaultTimeZone;
         localNotification.UserInfo  = NSDictionary.FromObjectAndKey(NSNumber.FromInt32(LocalNotificationUid), new NSString(PWMLocalNotificationUidKey));
         UIApplication.SharedApplication.ScheduleLocalNotification(localNotification);
     }
     return(LocalNotificationUid++);
 }
        public void RegisterNotification(string title, string body)
        {
            UNUserNotificationCenter     center = UNUserNotificationCenter.Current;
            UNMutableNotificationContent notificationContent = new UNMutableNotificationContent();

            notificationContent.Title = title;
            notificationContent.Body  = body;

            notificationContent.Sound = UNNotificationSound.Default;

            UNTimeIntervalNotificationTrigger trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false);

            UNNotificationRequest request = UNNotificationRequest.FromIdentifier("FiveSecond", notificationContent, trigger);

            center.AddNotificationRequest(request, (NSError obj) =>
            {
            });
        }